Answers for "get index of array javascript by object"

9

javascript indexOf object value in array

// Get index of object with specific value in array
const needle = 3; // needle
const haystack = [{ id: 1 }, { id: 2 }, { id: 3 }]; // haystack
const index = haystack.findIndex(item => item.id === needle);
Posted by: Guest on September-23-2020
0

find the index of an object in an array

const letters = [{letter: 'a'},{letter: 'b'},{letter: 'c'}]

const index = letters.findIndex((element, index) => {
  if (element.letter === 'b') {
    return true
  }
})

//index is `1`
Posted by: Guest on April-16-2021
0

js find index of object by value of property and return it's key

const index = Data.findIndex(item => item.name === 'John');
Posted by: Guest on April-23-2021

Code answers related to "get index of array javascript by object"

Code answers related to "Javascript"

Browse Popular Code Answers by Language