Categories
JavaScript Answers

How to filter array with multiple conditions with JavaScript?

Spread the love

To filter array with multiple conditions with JavaScript, we call the filter method.

For instance, we write

const filteredUsers = users.filter(
  (obj) => obj.name === filter.name && obj.address === filter.address
);

to call users.filter with a callback that gets the items with the name property of the obj being looped through equal to filter.name.

And we get the item in users with address property equal to filter.address.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *