The filter() method of an array filters elements to just those that pass the test in the provided function.
const words = ['bugs', 'ants', 'potatoes', 'tomatoes'];
const filter = words.filter((word) => word.length > 6);
console.log(filter);
// ['potatoes', 'tomatoes']
// common, more-advanced example
const places = [
{city: "Detroit", state: "Michigan"},
{city: "Miami", state: "Florida"},
{city: "Boston", state: "Massachusetts"},
{city: "New York", state: "New York"}
];
const placesFilterMichigan = places.filter(places =>
places.state == "Michigan"
);
console.log(placesFilterMichigan);
[ {city: "Detroit", state: "Michigan"} ]