array.filter()
The filter() method of Array instances creates a shallow copy of a portion of a given array, filtered down to just the elements from the given array that pass the test implemented by the provided function.
The filter() method of Array instances creates a shallow copy of a portion of a given array, filtered down to just the elements from the given array that pass the test implemented by the provided function.
let arrayAges = [14, 16, 17, 18, 19, 20, 21, 23];
let arrayAgesAdult = arrayAges.filter(checkAge);
arrayAgesAdult.forEach(print);
function checkAge(element) {
return element >= 18;
}
function print(x) {
console.log(x);
}