How to array filter with multiple values in javascript?

Today, We want to share with you javascript filter array multiple values.In this post we will show you javascript filter array values, hear for javascript filter array of objects by another array of objects we will give you demo and example for implement.In this post, we will learn about JavaScript Array Filter Method Filtering Arrays with an example.

JavaScript filtering array with multiple values

let numbers = [3, 7, 2, 15, 4, 9, 21, 14];

You want to filter the numbers to include only those higher than 3 and lower than 17.

do it with .filter():

Example 1:

let numbers = [3, 7, 2, 15, 4, 9, 21, 14];

let finalCleanResults = numbers.filter(function (isLatestGetParam) {
  return isLatestGetParam > 3 && isLatestGetParam < 17;
});

console.log(finalCleanResults);

The value of finalCleanResults will be [7, 15, 4, 9, 14]

return either true or false

let numbers = [3, 7, 2, 15, 4, 9, 21, 14];

let finalCleanResults = numbers.filter(function (isLatestGetParam) {
  if (isLatestGetParam > 3 && isLatestGetParam < 17) {
    return true;
  }
});

console.log(finalCleanResults);

Filter array of objects with multiple values

Example :
list of member data as follows:

let member = [
  {
    name: "Vishal",
    age: 27,
    country: "Rajkot",
  },
  {
    name: "Lalji",
    age: 23,
    country: "Mubai",
  },
  {
    name: "Jayesh",
    age: 29,
    country: "Bhavvnagar",
  },
  {
    name: "Ella",
    age: 24,
    country: "Gondal",
  },
  {
    name: "Jagruti",
    age: 24,
    country: "Rajkot",
  },
];
let filteredMember = member.filter(function (isLatestGetParam) {
  // the current value is an object, so you can check on its properties
  return isLatestGetParam.country === "Rajkot" && isLatestGetParam.age < 25;
});

console.log(filteredMember);

Only the last element will match the filter:

{name: "Jagruti", age: 24, country: "Rajkot"}

I hope you get an idea about JavaScript Array filter() Method.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment