angular 10 find in array code example

Example 1: find typescript

const inventory = [
    {name: 'apples', quantity: 2},
    {name: 'bananas', quantity: 0},
    {name: 'cherries', quantity: 5}
];

function findCherries(fruit) { 
    return fruit.name === 'cherries';
}

inventory.find(findCherries); // { name: 'cherries', quantity: 5 }

/* OR */
  inventory.filter(x => x.name === 'bananas')[0]; // { name: 'bananas', quantity:0}  

/* OR */

inventory.find(e => e.name === 'apples'); // { name: 'apples', quantity: 2 }

Example 2: how to find element in array angularjs

$filter('filter')(myArray, {'id':73})

Example 3: how to find element in array angularjs

comment by pritesh