Answers for "find in array of objects javascript on id"

62

find in array of objects javascript

let arr = [
    { name:"string 1", value:"this", other: "that" },
    { name:"string 2", value:"this", other: "that" }
];

let obj = arr.find(o => o.name === 'string 1');

console.log(obj);
Posted by: Guest on May-08-2020
0

method to look for objects in arrays by id

//Lets say you have an array and you want to find "bar" for an object but you want to find that object by ID
myArray = [{'id':'73','foo':'bar'},{'id':'45','foo':'barrr'}]

//use find()
myArray.find(x => x.id === '45').foo; //returns 'barrr'
Posted by: Guest on April-09-2022

Code answers related to "find in array of objects javascript on id"

Code answers related to "Javascript"

Browse Popular Code Answers by Language