typescript array map filter code example

Example 1: use .map(), .filter() js

var arr = [1, 25, 20, 4];

var sum = arr.map((item) => item * 10).filter((item) => item > 100);
var sum2 = arr.map((item) => item * 10)
console.log("sum2", sum2)
// sum2 : (4) [10, 250, 200, 40]
console.log("sum", sum);
// sum : (2) [250, 200]

Example 2: angular array filter typescript

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

Example 3: js map filter reduce

const numbers = [1, 2, 3, 4];
const doubled = numbers.map(item => item * 2);
console.log(doubled); // [2, 4, 6, 8]

Example 4: js map filter reduce

const numbers = [1, 2, 3, 4];
const sum = numbers.reduce(function (result, item) {
  return result + item;
}, 0);
console.log(sum); // 10