tyoescript where array code example
Example 1: angular array filter typescript
ngOnInit() {
this.booksByStoreID = this.books.filter(
book => book.store_id === this.store.id);
}
Example 2: 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);
inventory.filter(x => x.name === 'bananas')[0];
inventory.find(e => e.name === 'apples');