Sometimes, we want to filter array of objects with JavaScript.
In this article, we’ll look at how to filter array of objects with JavaScript.
How to filter array of objects with JavaScript?
To filter array of objects with JavaScript, we call the filter method.
For instance, we write
const foundNames = names.filter((v) => v.name === "Joe" && v.age < 30);
to call names.filter with a callback that checks if the name property is 'Joe' and the age property is less than 30.
Then objects that meet these conditions are returned in a new array.
Conclusion
To filter array of objects with JavaScript, we call the filter method.