mdn filter() code example
Example 1: angular array filter typescript
ngOnInit() {
this.booksByStoreID = this.books.filter(
book => book.store_id === this.store.id);
}
Example 2: .filter js
const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
const result = words.filter(word => word.length > 6);
console.log(result);
Example 3: javascript filter
const filtered = array.filter(item => {
return item < 20;
});
Example 4: filter typescript
this.booksByStoreID = this.books.filter(book => book.store_id === this.store.id);
Example 5: filter javascript
function filter(array, filterfunc) {
let filteredArray = [];
for (let i = 0; i < array.length; i++) {
let result = filterfunc(array[i], i, array);
if (result) {
filteredArray.push(array[i]);
}
}
return filteredArray;
};