find property in array of objects javascript code example
Example 1: javascript find object by property in array
myObj = myArrayOfObjects.find(obj => obj.prop === 'something');
Example 2: js find element in array by property
var result = jsObjects.find(obj => {
return obj.b === 6
})
Example 3: 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 4: javascript find object in array by property value
const fruits = ['apple', 'banana', 'grapes', 'mango', 'orange'];
const filterItems = (needle, heystack) => {
let query = needle.toLowerCase();
return heystack.filter(item => item.toLowerCase().indexOf(query) >= 0);
}
console.log(filterItems('ap', fruits));
console.log(filterItems('ang', fruits));
Example 5: find object in array javascript with property
let obj = objArray.find(obj => obj.id == 3);
Example 6: search an array of objects with specific object property value
var result = jsObjects.find(obj => {
return obj.b === 6
});