filter method in array

The filter() method creates a new array filled with elements that pass a test provided by a function. The filter() method does not execute the function for empty elements. The filter() method does not change the original array.
 avatar
Pranav
javascript
2 years ago
234 B
4
Indexable
Never

//array.filter(function(currentValue, index, arr), thisValue)

const ages = [38, 23, 16, 40, 7];

const result = ages.filter(checkAdult);

function checkAdult(age) {
  return age >= 18;
}

console.log(result)

//output [ 38, 23, 40 ]