Categories
JavaScript Answers

How to filter an array or object by checking multiple values with JavaScript?

Spread the love

To filter an array or object by checking multiple values with JavaScript, we use the filter method.

For instance, we write

const find = myArray.filter((result) => {
  return result.param1 === "string1" && result.param2 === "string2";
});

to call myArray.filter with a function that checks if the result object in myArray that’s being looped through has the params1 property equal to 'string1' and params2 equals to 'string2'.

An array with the objects that meets the condition is returned.

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 *