You can use the Array.prototype.filter method:

var newArray = homes.filter(function (el) {
  return el.price <= 1000 &&
         el.sqft >= 500 &&
         el.num_of_beds >=2 &&
         el.num_of_baths >= 2.5;
});

Live Example:

var obj = {
    'homes': [{
            "home_id": "1",
            "price": "925",
            "sqft": "1100",
            "num_of_beds": "2",
            "num_of_baths": "2.0",
        }, {
            "home_id": "2",
            "price": "1425",
            "sqft": "1900",
            "num_of_beds": "4",
            "num_of_baths": "2.5",
        },
        // ... (more homes) ...     
    ]
};
// (Note that because `price` and such are given as strings in your object,
// the below relies on the fact that <= and >= with a string and number
// will coerce the string to a number before comparing.)
var newArray = obj.homes.filter(function (el) {
  return el.price <= 1000 &&
         el.sqft >= 500 &&
         el.num_of_beds >= 2 &&
         el.num_of_baths >= 1.5; // Changed this so a home would match
});
console.log(newArray);

This method is part of the new ECMAScript 5th Edition standard, and can be found on almost all modern browsers.

For IE, you can include the following method for compatibility:

if (!Array.prototype.filter) {
  Array.prototype.filter = function(fun /*, thisp*/) {
    var len = this.length >>> 0;
    if (typeof fun != "function")
      throw new TypeError();

    var res = [];
    var thisp = arguments[1];
    for (var i = 0; i < len; i++) {
      if (i in this) {
        var val = this[i];
        if (fun.call(thisp, val, i, this))
          res.push(val);
      }
    }
    return res;
  };
}
Answer from Christian C. Salvadó on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › filter
Array.prototype.filter() - JavaScript | MDN
December 13, 2025 - The following example uses filter() to create a filtered array of all objects with non-zero, numeric id.
Top answer
1 of 16
1005

You can use the Array.prototype.filter method:

var newArray = homes.filter(function (el) {
  return el.price <= 1000 &&
         el.sqft >= 500 &&
         el.num_of_beds >=2 &&
         el.num_of_baths >= 2.5;
});

Live Example:

var obj = {
    'homes': [{
            "home_id": "1",
            "price": "925",
            "sqft": "1100",
            "num_of_beds": "2",
            "num_of_baths": "2.0",
        }, {
            "home_id": "2",
            "price": "1425",
            "sqft": "1900",
            "num_of_beds": "4",
            "num_of_baths": "2.5",
        },
        // ... (more homes) ...     
    ]
};
// (Note that because `price` and such are given as strings in your object,
// the below relies on the fact that <= and >= with a string and number
// will coerce the string to a number before comparing.)
var newArray = obj.homes.filter(function (el) {
  return el.price <= 1000 &&
         el.sqft >= 500 &&
         el.num_of_beds >= 2 &&
         el.num_of_baths >= 1.5; // Changed this so a home would match
});
console.log(newArray);

This method is part of the new ECMAScript 5th Edition standard, and can be found on almost all modern browsers.

For IE, you can include the following method for compatibility:

if (!Array.prototype.filter) {
  Array.prototype.filter = function(fun /*, thisp*/) {
    var len = this.length >>> 0;
    if (typeof fun != "function")
      throw new TypeError();

    var res = [];
    var thisp = arguments[1];
    for (var i = 0; i < len; i++) {
      if (i in this) {
        var val = this[i];
        if (fun.call(thisp, val, i, this))
          res.push(val);
      }
    }
    return res;
  };
}
2 of 16
66

I'm surprised no one has posted the one-line response:

const filteredHomes = json.homes.filter(x => x.price <= 1000 && x.sqft >= 500 && x.num_of_beds >=2 && x.num_of_baths >= 2.5);

...and just so you can read it easier:

const filteredHomes = json.homes.filter( x => 
  x.price <= 1000 && 
  x.sqft >= 500 && 
  x.num_of_beds >=2 && 
  x.num_of_baths >= 2.5
);
Discussions

Filter array in objects array
Hello everyone, I have the following construct: const allProducts = [ { img:" xyz", desc: "xyz", categories:["Men", "Sportshoes"]; } ] I want to get all products, where categories includes Men. I tried: allProducts.filter((item)=>item.categories.includes("Men")) also: allProducts.filter((i... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
1
0
January 3, 2023
How to filter array of object keys against an array of strings
You guys are awesome! Thank you so much. Non-Toxic and so much better than Stack Overflow. I've never gotten nearly as much support there as I have here. More on reddit.com
🌐 r/learnjavascript
22
12
May 1, 2023
How to filter an array in array of objects in Javascript? - Stack Overflow
They're both about arrays of objects, but the comparison method for the property is completely different. ... filter() -> uses a callback function the return value of which decides what will be returned in the filtered array. More on stackoverflow.com
🌐 stackoverflow.com
Filter array of object - JavaScript - SitePoint Forums | Web Development & Design Community
I have an array of object. Something like: var data = [ {id: 1, string: "Lets go home"}, {id: "John is better than me", string: "I'm ok"}, {id: "last but not least", string: "for sure"}, ]; I need to filter the array , removing the field that contains a word. More on sitepoint.com
🌐 sitepoint.com
0
January 19, 2018
🌐
Reddit
reddit.com › r/javascripttips › how to filter array of objects by value in javascript
r/JavaScriptTips on Reddit: How to Filter Array of Objects by Value in JavaScript
April 14, 2023 -

If you're working with arrays of objects in JavaScript, you may find yourself needing to filter the array based on a specific value. Luckily, JavaScript provides us with a built-in method to do just that: Array.filter() . In this article, we'll explore how to to filter an array of objects by value.

Let's say we have an array of objects representing different people, with properties like "name", "age", and "occupation". We want to filter this array to only include people who are over the age of 30. Here's how we could do it:

const people = [
  { name: "Alice", age: 25, occupation: "Engineer" },
  { name: "Bob", age: 35, occupation: "Teacher" },
  { name: "Charlie", age: 42, occupation: "Doctor" },
  { name: "Dave", age: 28, occupation: "Writer" },
];

const filteredPeople = people.filter((person) => person.age > 30);

console.log(filteredPeople);
// Output: [{ name: "Bob", age: 35, occupation: "Teacher" }, { name: "Charlie", age: 42, occupation: "Doctor" }]

Here, we're using the filter() method on the people array, and passing in a function as an argument. This function takes each object in the array as its argument (which we've named person), and returns a boolean value indicating whether that object should be included in the filtered array.

In this case, we're using a simple comparison to check if the person's age is greater than 30. If it is, the function returns true, and the person is included in the filtered array. If not, the function returns false, and the person is excluded.

This is just one example of how you can use Array.filter() to filter an array of objects by value. Depending on your specific use case, you may need to use more complex comparison logic or filter on different properties of the objects in the array. But with Array.filter( as your tool, you'll be able to filter your arrays with ease.

🌐
W3Schools
w3schools.com › jsref › jsref_filter.asp
JavaScript Array filter() Method
❮ Previous JavaScript Array Reference ... { return age >= 18; } Try it Yourself » · The filter() method creates a new array filled with elements that pass a test provided by a function....
🌐
freeCodeCamp
freecodecamp.org › news › filter-arrays-in-javascript
How to Filter an Array in JavaScript – JS Filtering for Arrays and Objects
November 7, 2024 - You can then use the filter() method to filter through the array and return a new array of filtered elements. Let's say you have an object that holds users' details like name, age and occupation.
Find elsewhere
🌐
Reddit
reddit.com › r/learnjavascript › how to filter array of object keys against an array of strings
r/learnjavascript on Reddit: How to filter array of object keys against an array of strings
May 1, 2023 -

Trying to simplify this as much as possible from a bigger example.

I am trying to filter through an array of objects (productList) by matching against an array of strings.

Ex:

productList = [
    {
        id: 0,
        productName: "Women's Merrell Hiking Boots",
        price: 65.00,
        brand: "Merrell",
        mainCategory: "Footwear",
        color: "green"
    },
    {
        id: 1,
        productName: "Natural Walking Stick",
        price: 22.00,
        brand: "Fayet",
        mainCategory: "Outdoors"
    }
]

I have a function that builds an array of strings by clicking on checkboxes which comes out to the following (checkedCount).

checkedCount = ["Merrell", "Fayet", "Outdoors"]

Is there a way to filter through the product list to see if an array of string values match a product list value?

I have the following, but I am minimized to a single key at a time ("brand" in this case).

productList.filter(product => product.brand.includes(checkedCount))

Is there some way to make this more generic where I could say and product key?
Ex:

productList.filter(product => product.[AnyKeyFromProductList like id, productName, price, brand, mainCategory].includes(checkedCount))
Top answer
1 of 7
4
You guys are awesome! Thank you so much. Non-Toxic and so much better than Stack Overflow. I've never gotten nearly as much support there as I have here.
2 of 7
2
const filterProps = ['id', 'productName', 'price', 'brand', 'mainCategory'] const productList = [ { id: 0, productName: "Women's Merrell Hiking Boots", price: 65.0, brand: "Merrell", mainCategory: "Footwear", color: "green", }, { id: 1, productName: "Natural Walking Stick", price: 22.0, brand: "Fayet", mainCategory: "Outdoors", }, ]; // instance input(?) const checkedCount = ["Merrell", "Fayet", "Outdoors"]; // weird naming, I dont understand what this is but I'm reuing it function filterProductsByCheckedCount (filters) { return productList.filter((product) => { return filterProps.some((prop) => { return filters.includes(product[prop]); }); }); } console.log(filterProductsByCheckedCount(checkedCount)); You want to pass your selected values to filterProductsByCheckedCount which already knows about productList and filterProps. Iterate over the product list and check each product in the list to see if any of the values for properties in filterProps on the given product match the values provided by checkedCount. You're comparing a list against two lists. That solution is O(n^3) but you can refactor it to be much more efficient using hash maps if you're dealing with large datasets (unless they’re so large you’re dealing with memory complexity but given this question I don’t think you need to worry about that). Edit: I looked at the other answers here and they're all wrong, irrelevant, or lazy. Your filters and input match both products in the list so running that on my machine gave me the correct answer but you need to beef up the data set to verify it.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-filter-object-array-based-on-attributes
How to Filter Object Array based on Attributes? - GeeksforGeeks
July 23, 2025 - One can use the filter() and reduce() functions in JavaScript to filter the object array based on attributes. The filter() function will return a new array containing all the array elements that pass the given condition.
🌐
DigitalOcean
digitalocean.com › community › tutorials › js-filter-array-method
How To Use the filter() Array Method in JavaScript | DigitalOcean
August 26, 2021 - Use filter() on arrays to go through an array and return a new array with the elements that pass the filtering rules.
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › filter-array-of-objects
Filter an Array of Objects in JavaScript - Mastering JS
August 10, 2020 - JavaScript arrays have a `filter()` method that quickly lets you get just the elements of an array that match a given condition. Here's how you can use it to filter an array of objects.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-filter-an-array-of-objects-in-es6
How to filter an array of objects in ES6 ? - GeeksforGeeks
July 3, 2024 - For filtering out contents from the array of objects we would be using at first the filter() method which we would be applying on our outermost array part.
🌐
Built In
builtin.com › software-engineering-perspectives › javascript-filter
How to Filter a JavaScript Array With the Filter() Method | Built In
Define the array of objects. Call the filter() method on array and return the new array that contains only the elements that matches the condition. Console the new array to check the output.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › find
Array.prototype.find() - JavaScript | MDN
If you need to find if a value exists in an array, use includes(). Again, it checks each element for equality with the value instead of using a testing function. If you need to find if any element satisfies the provided testing function, use some(). If you need to find all elements that satisfy the provided testing function, use filter().
🌐
React
react.dev › learn › rendering-lists
Rendering Lists – React
You can use JavaScript’s filter() method to return just those people. This method takes an array of items, passes them through a “test” (a function that returns true or false), and returns a new array of only those items that passed the test (returned true).
🌐
Server Side Up
serversideup.net › blog › filter-sort-and-search-arrays-with-javascript
Filter, Sort, and Search Arrays with JavaScript | Server Side Up
October 4, 2022 - What this allows us to do is take into account whether the user wants to turn on or off filtering of even numbers (const filterEvenNumbers = ref(true)). We then return either all of the numbers, or the filtered sub-set of numbers. That way we can display or work with filteredNumbers and then have a switch that the user can toggle. The computed() property handled by Vue will reactively update our display depending on what the user needs. Pretty slick! It gets even more functional when you can filter object arrays with JavaScript.
🌐
SitePoint
sitepoint.com › javascript
Filter array of object - JavaScript - SitePoint Forums | Web Development & Design Community
January 19, 2018 - function includesStr(values, str) { return values.map(function (value) { return String(value); }).find(function (value) { return value.includes("Lets"); }); } var data = [ {id: 1, string: "Lets go home"}, {id: "John is better than me", string: "I'm ok"}, {id: "last but not least", string: "for sure"}, ]; var filtered = data.filter(function (item) { return !includesStr(Object.values(item), "Lets"); }); console.log(filtered); ... Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor.
🌐
YouTube
youtube.com › shorts › H72MvbC3p9o
Filter an Array of Objects with JavaScript - YouTube
In this short I'll show you how to use the JavaScript array filter method to filter an array of objects. This task is frequently necessary when working with ...
Published   July 28, 2023