filter out items from array 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: 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
  });