filter typescript code example

Example 1: angular array filter typescript

ngOnInit() {
  this.booksByStoreID = this.books.filter(
          book => book.store_id === this.store.id);
}

Example 2: how to use filter in typescript

var numbers = [1, 3, 6, 8, 11];

var lucky = numbers.filter(function(number) {
  return number > 7;
});

// [ 8, 11 ]

Example 3: filter array react

<div>
  {people.filter(person => 
    person.age < 60).map(filteredPerson => (
    <li>
      {filteredPerson.name}
    </li>
  ))}
</div>

Example 4: typescript filter list by property

const object = {
  firstAttribute: 'firstValue',
  secondAttribute: 'secondValue'
};  

objectList.filter(o -> o.firstAttribute === 'firstValue');

Example 5: js filter

//ES6
let greaterTen = numbers.filter(number => { number > 10 });
console.log(greaterTen); // []

// with return
let greaterTen = numbers.filter(number => number > 10 ); // return implicito
console.log(greaterTen); // [23, 12, 45, 78, 11, 10.1, 84]

// ES5
var greaterTen = numbers.filter(function(){ 
  number > 10 
});
console.log(greaterTen); // []

// with return
var greaterTen = numbers.filter(function(){ 
  return number > 10 
});
console.log(greaterTen);  // [23, 12, 45, 78, 11, 10.1, 84]

Example 6: filter typescript

this.booksByStoreID = this.books.filter(book => book.store_id === this.store.id);