how to filter an element in array javascript code example

Example 1: array.filter in js

var numbers = [1, 3, 6, 8, 11];

var lucky = numbers.filter(function(number) {
  return number > 7;
});

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
  });