how the filter() function works javascript
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const filter = arr.filter((number) => number > 5);
console.log(filter); // [6, 7, 8, 9]
how the filter() function works javascript
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
const filter = arr.filter((number) => number > 5);
console.log(filter); // [6, 7, 8, 9]
how to create my own filter in js
// filter takes an array and function as argumentfunction
filter(arr, filterFunc) {
const filterArr = []; // empty array
// loop though array
for(let i=0;i<arr.length;i++) {
const result = filterFunc(arr[i], i, arr);
// push the current element if result is true
if(result)
filterArr.push(arr[i]);
}
return filterArr;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us