array filter example
Example 1: filter javascript array
var words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
const result = words.filter(word => word.length > 6);
console.log(result);
Example 2: filter in js
const filterThisArray = ["a","b","c","d","e"]
console.log(filterThisArray)
const filteredThatArray = filterThisArray.filter((item) => item!=="e")
console.log(filteredThatArray)
Example 3: javascript filter array of objects
function isBigEnough(value) {
return value >= 10
}
let filtered = [12, 5, 8, 130, 44].filter(isBigEnough)
Example 4: 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;
};