.find angular code example
Example 1: 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);
Example 2: javascript find
const inventory = [
{name: 'apples', quantity: 2},
{name: 'cherries', quantity: 8}
{name: 'bananas', quantity: 0},
{name: 'cherries', quantity: 5}
{name: 'cherries', quantity: 15}
];
const result = inventory.find( ({ name }) => name === 'cherries' );
console.log(result)
Example 3: javascript find object by property in array
myObj = myArrayOfObjects.find(obj => obj.prop === 'something');
Example 4: find a single element in array of objects javascript
myArray.find(x => x.id === '45').foo;
Example 5: .find angular how does it work
this.attr_0 = this.attr_1.find(x => x.id === someId);