js ary filter 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: array.filter in js
var numbers = [1, 3, 6, 8, 11];
var lucky = numbers.filter(function(number) {
return number > 7;
});
Example 3: filter array js
const arr = ['pine', 'apple', 'pineapple', 'ball', 'roll'];
const longWords = arr.filter(item => item.length > 5);
console.log(longWords);
Example 4: filter an array in Javascript
1let greaterTen = [];2
3for (let i = 0; i<numbers.length; i++) {4 var currentNumber = numbers[i];5 if (currentNumber > 10) {6 greaterTen.push(currentNumber)7 }8}9
10console.log(greaterTen);