Answers for "indexof for array of objects"

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
3

using index of on array of objects

arr = [{x: "a", y: 1}, {x: "something", y: 2}]
arr.findIndex(obj => obj.x === "a" && obj.y === 1);
Posted by: Guest on June-10-2020
2

index of value in array

// for dictionary case use findIndex 
var imageList = [
   {value: 100},
   {value: 200},
   {value: 300},
   {value: 400},
   {value: 500}
];
var index = imageList.findIndex(img => img.value === 200);
Posted by: Guest on June-27-2020

Code answers related to "indexof for array of objects"

Code answers related to "Javascript"

Browse Popular Code Answers by Language