TypeScript Filter Angular Array
ngOnInit() {
this.booksByStoreID = this.books.filter(
book => book.store_id === this.store.id);
}
Bad Badger
ngOnInit() {
this.booksByStoreID = this.books.filter(
book => book.store_id === this.store.id);
}
const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
const threeLetterWords = words.filter(word => word.length <= 5)
console.log(threeLetterWords);
// RESULT: (3) ["spray", "limit", "elite"]
const myNum = [2,3,4,5,6,7,8,9,10];
//using filter gives us a new array
const divisibleBy3 = myNum.filter(eachNum => eachNum%3==0);
console.log(divisibleBy3); //output:[3,6,9]
const numbers = [2, 4, 5, 3, 8, 9, 11, 33, 44];
const filterNumbers = numbers.filter((number) => number > 5);
console.log(filterNumbers)
//Expected output:[ 8, 9, 11, 33, 44 ]
/*
Filter
- Filter Longest Word By Number
*/
// Filter Words More Than 4 Characters
let sentence = "I Love Foood Code Too Playing Much";
let smallWords = sentence
.split(" ")
.filter(function (ele) {
return ele.length <= 4;
})
.join(" ");
console.log(smallWords);
// Ignore Numbers
let ignoreNumbers = "Elz123er4o";
let ign = ignoreNumbers
.split("")
.filter(function (ele) {
return isNaN(parseInt(ele));
})
.join("");
console.log(ign);
// Filter Strings + Multiply
let mix = "A13BS2ZX";
let mixedContent = mix
.split("")
.filter(function (ele) {
return !isNaN(parseInt(ele));
})
.map(function (ele) {
return ele * ele;
})
.join("");
console.log(mixedContent);
const randomNumbers = [4, 11, 42, 14, 39];
const filteredArray = randomNumbers.filter(n => {
return n > 5;
});