1ngOnInit() {
2 this.booksByStoreID = this.books.filter(
3 book => book.store_id === this.store.id);
4}
1<div>
2 {people.filter(person =>
3 person.age < 60).map(filteredPerson => (
4 <li>
5 {filteredPerson.name}
6 </li>
7 ))}
8</div>
1const object = {
2 firstAttribute: 'firstValue',
3 secondAttribute: 'secondValue'
4};
5
6objectList.filter(o -> o.firstAttribute === 'firstValue');
1var numbers = [1, 3, 6, 8, 11];
2
3var lucky = numbers.filter(function(number) {
4 return number > 7;
5});
6
7// [ 8, 11 ]
1//ES6
2let greaterTen = numbers.filter(number => { number > 10 });
3console.log(greaterTen); // []
4
5// with return
6let greaterTen = numbers.filter(number => number > 10 ); // return implicito
7console.log(greaterTen); // [23, 12, 45, 78, 11, 10.1, 84]
8
9// ES5
10var greaterTen = numbers.filter(function(){
11 number > 10
12});
13console.log(greaterTen); // []
14
15// with return
16var greaterTen = numbers.filter(function(){
17 return number > 10
18});
19console.log(greaterTen); // [23, 12, 45, 78, 11, 10.1, 84]