find object in array javascript by property value code example
Example 1: js get array item by property
const jsObjects = [
{id: 1, displayName: "First"},
{id: 2, displayName: "Second"},
{id: 3, displayName: "Third"},
{id: 4, displayName: "Fourth"}
]
var result = jsObjects.find(obj => {
return obj.id === 1
})
console.log(result)
Example 2: javascript find object by property in array
myObj = myArrayOfObjects.find(obj => obj.prop === 'something');
Example 3: js find element in array by property
var result = jsObjects.find(obj => {
return obj.b === 6
})
Example 4: how to find id in array javascript
const array1 = [5, 12, 8, 130, 44];
const found = array1.find(element => element > 10);
console.log(found);
Example 5: find object in array javascript with property
let obj = objArray.find(obj => obj.id == 3);
Example 6: js find value in array
const array1 = [5, 12, 8, 130, 44];
const found = array1.find(element => element > 10);
console.log(found);