findIndex


If the array item is an object, you can use the findIndex method

const letters = [ 
  {
    letter: 'A',
  },
  {
    letter: 'B',
  },
  {
    letter: 'C',
  },
]

const index = letters.findIndex((element, index) => {
  if (element.letter === 'B') {
    return true
  }
})
console.log(index); // 1




© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext