1ngOnInit() {
2 this.booksByStoreID = this.books.filter(
3 book => book.store_id === this.store.id);
4}
1var words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
2
3const result = words.filter(word => word.length > 6);
4
5console.log(result);
1const arr = [1, 2, 3, 4, 5, 6];
2const filtered = arr.filter(el => el === 2 || el === 4); //[2, 4]
1const filtered = array.filter(item => {
2 return item < 20;
3});
4// An example that will loop through an array
5// and create a new array containing only items that
6// are less than 20. If array is [13, 65, 101, 19],
7// the returned array in filtered will be [13, 19]
1const numbers = [2, 4, 5, 3, 8, 9, 11, 33, 44];
2const filterNumbers = numbers.filter((number) => number > 5);
3console.log(filterNumbers)
4//Expected output:[ 8, 9, 11, 33, 44 ]
1const myNum = [2,3,4,5,6,7,8,9,10];
2//using filter gives us a new array
3const divisibleBy3 = myNum.filter(eachNum => eachNum%3==0);
4console.log(divisibleBy3); //output:[3,6,9]