The filter method takes an callback and applies the callback for each item in the array, if the callback returns true for an item, that item is placed in a new array.

After the callback is applied to all items, the new array is returned.

let family = [{"name":"Jack",  "age": 26},
{"name":"Jill", "age": 22},
{"name":"James", "age": 5 },
{"name":"Jenny", "age": 2 }];

let adults_ES5 = family.filter(function (person) {
return person.age > 18;
});

let adults_ES6 = family.filter(person => person.age > 18);

// Log people who are over 18 years old.
console.log(adults_ES5); // [{"name":"Jack", "age": 26}, {"name":"Jill", "age": 22}]
console.log(adults_ES6); // [{"name":"Jack", "age": 26}, {"name":"Jill", "age": 22}]


Resources: