node.js .filter code example
Example 1: 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"]
Example 2: javascript array filter
run.addEventListener("click", function () {
let array = [];
people.forEach((elem) => {
// elem before age to target
if (elem.age > 18) {
array.push(elem); // each array elem > 18 is "pushed" inside the new array
// console.log(array); nope : messes things up
} else {
(""); // no need to declare this through console.log
}
});
console.log(array); //and there you have it : filtered array
});