filter return processed value javascript code example
Example 1: javascript array filter elements greater than
function isGreater(element, index, array) {
return (element >= 10);
}
let testElemets = [12, 5, 8, 130, 44].filter(isGreater);
console.log("Test Value : " + testElemets );
Example 2: array filter
const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
const result = words.filter(word => word.length > 6);
console.log(result);
// expected output: Array ["exuberant", "destruction", "present"]