javascript find array object code example
Example 1: javascript find object by property in array
myObj = myArrayOfObjects.find(obj => obj.prop === 'something');
Example 2: javascript find object in array
myArray.findIndex(x => x.id === '45');
Example 3: javascript find object array
const found = accesses.find(x => x.Resource === 'Clients');
console.log(found)
Example 4: return object list in find js
const inventory = [
{name: 'apples', quantity: 2},
{name: 'bananas', quantity: 0},
{name: 'cherries', quantity: 5}
];
function isCherries(fruit) {
return fruit.name === 'cherries' && fruit.name === 'bananas';
}
console.log(inventory.find(isCherries));