jeudi 28 octobre 2021

How to compare items in array using index numbers?

How can I compare one item in array to it's next or previous item using index numbers Take the code below as example

const arr = [
  {
    name: "A",
    marks: 20,
  },
  {
    name: "B",
    marks: 25,
  },
  {
    name: "C",
    marks: 30,
  },
];

So how can I compare B with A or C in an if statement using index numbers to get something done?

Aucun commentaire:

Enregistrer un commentaire