js how filter works code 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: javascript array filter
var newArray = array.filter(function(item) {
return condition;
});
Example 3: how to create my own filter in js
filter(arr, filterFunc) {
const filterArr = [];
for(let i=0;i<arr.length;i++) {
const result = filterFunc(arr[i], i, arr);
if(result)
filterArr.push(arr[i]);
}
return filterArr;
}