You could filter it and search just for one occurence of the search string.

Methods used:

  • Array#filter, just for filtering an array with conditions,

  • Object.keys for getting all property names of the object,

  • Array#some for iterating the keys and exit loop if found,

  • String#toLowerCase for getting comparable values,

  • String#includes for checking two string, if one contains the other.

function filterByValue(array, string) {
    return array.filter(o =>
        Object.keys(o).some(k => o[k].toLowerCase().includes(string.toLowerCase())));
}

const arrayOfObject = [{ name: 'Paul', country: 'Canada', }, { name: 'Lea', country: 'Italy', }, { name: 'John', country: 'Italy' }];

console.log(filterByValue(arrayOfObject, 'lea')); // [{name: 'Lea', country: 'Italy'}]
console.log(filterByValue(arrayOfObject, 'ita')); // [{name: 'Lea', country: 'Italy'}, {name: 'John', country: 'Italy'}]
.as-console-wrapper { max-height: 100% !important; top: 0; }

Answer from Nina Scholz on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › filter
Array.prototype.filter() - JavaScript | MDN
The filter() method reads the length property of this and then accesses each property whose key is a nonnegative integer less than length. ... const arrayLike = { length: 3, 0: "a", 1: "b", 2: "c", 3: "a", // ignored by filter() since length is 3 }; console.log(Array.prototype.filter.call(...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › filter-array-of-objects-with-another-array-of-objects-in-javascript
Filter Array of Objects with Another Array of Objects in JavaScript - GeeksforGeeks
August 5, 2025 - Below are the approaches to filter ... approach, we are using the filter method combined with includes to create a filteredArray that contains objects from mainArray whose IDs are present in filterArray....
🌐
TutorialsPoint
tutorialspoint.com › filter-array-with-filter-and-includes-in-javascript
Filter array with filter() and includes() in JavaScript
In the following program, we declared array1 and array2 and initialized names to filter array1 to include only the elements present in array2 using filter() and includes() method together. const array1 = ['John', 'David', 'Mike','Sam','Carol','Bob']; const array2 = ['David', 'Sam', 'Bob', 'Indu']; ...
🌐
W3Schools
w3schools.com › jsref › jsref_filter.asp
JavaScript Array filter() Method
Array[ ] Array( ) at() concat() constructor copyWithin() entries() every() fill() filter() find() findIndex() findLast() findLastIndex() flat() flatMap() forEach() from() includes() indexOf() isArray() join() keys() lastIndexOf() length map() of() pop() prototype push() reduce() reduceRight() rest (...) reverse() shift() slice() some() sort() splice() spread (...) toReversed() toSorted() toSpliced() toString() unshift() values() valueOf() with() JS Boolean
🌐
Medium
medium.com › @melaniecp › filtering-an-arrays-objects-based-on-a-value-in-a-key-value-array-using-filter-and-includes-27268968308f
Filtering an array’s objects, based on a value in a key value array, using filter() and includes(), with JavaScript | by Melanie Phillips | Medium
April 8, 2019 - For each object key “ages”, we run the includes() method over the array of values. If it contains the value we’re looking for, in this case the integer 8 (for 8 years old), then it will keep that object for the new array because it returned ...
🌐
Built In
builtin.com › software-engineering-perspectives › javascript-filter
How to Filter a JavaScript Array With the Filter() Method | Built In
We used the filter() method on the freelancers array and passed a function that checks if each freelancer is skilled in JavaScript. If the skill matched the condition, the object was included in the new array filter_freelancers.
Find elsewhere
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › filter-array-of-objects
Filter an Array of Objects in JavaScript - Mastering JS
Here's how you can use Array#filter() to filter an array of characters given that the series property is an array: const characters = [ { name: 'James T. Kirk', series: ['Star Trek'] }, { name: 'Spock', series: ['Star Trek', 'Star Trek: The Next Generation'] }, { name: 'Jean-Luc Picard', series: ['Star Trek: The Next Generation'] }, { name: 'Worf', series: ['Star Trek: The Next Generation', 'Star Trek: Deep Space Nine'] } ]; const tngCharacters = characters.filter(character => { return character.series.includes('Star Trek: The Next Generation'); });
🌐
GitHub
gist.github.com › jherax › f11d669ba286f21b7a2dcff69621eb72
Filters an array of objects with multiple match-criteria. · GitHub
Coz what i was doing initially was evaluating to something like: return "PETER".includes("PETER") same thing for indexOf. so the results were inaccurate for me. const multiFilter = (arr, filters) => { let filterKeys = Object.keys(filters); return arr.filter(eachObj => { return filterKeys.every(eachKey => { if (!filters[eachKey].length) { return true; // passing an empty filter means that filter is ignored.
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
);
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript array methods › array.prototype.filter()
JavaScript Array filter() Method
November 7, 2024 - Because we pass in the range object, ... ... Remember the rule: Filter keeps true. Use the array filter() method to return an array of elements that pass a test function....
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-filter-array-of-objects-based-on-property
Filter an Array of Objects based on a property - JavaScript | bobbyhadz
On each iteration, check if the object's property points to the specified value. The Array.filter() method will return an array with all objects that meet the condition.
🌐
SitePoint
sitepoint.com › javascript
Filter array of object - JavaScript - SitePoint Forums | Web Development & Design Community
January 19, 2018 - data = data.filter(function (item) { console.log(Object.values(item)); return !item.string.includes("Lets"); }); The Object.values method gives an array, so we can filter that, but in this case we can return if didn’t find anything with the array find method.
🌐
Towards Data Science
towardsdatascience.com › home › latest › should you use .includes or .filter to check if an array contains an item?
Should You Use .includes or .filter to Check if An Array Contains an Item? | Towards Data Science
March 5, 2025 - Wrapping up, we’ve found that JavaScript’s built-in .includes() method is the fastest way to check if a JavaScript array contains an item, unless you have an array with a lot of items.
🌐
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.
🌐
Vultr Docs
docs.vultr.com › javascript › standard-library › Array › filter
JavaScript Array filter() - Filter Array Elements | Vultr Docs
November 28, 2024 - Have an array of objects where each object contains multiple properties. Use filter() to select objects that satisfy more complex conditions. ... const people = [ { name: "Alice", age: 25 }, { name: "Bob", age: 20 }, { name: "Charlie", age: ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › includes
Array.prototype.includes() - JavaScript | MDN
const array = [1, 2, 3]; console.log(array.includes(2)); // Expected output: true const pets = ["cat", "dog", "bat"]; console.log(pets.includes("cat")); // Expected output: true console.log(pets.includes("at")); // Expected output: false ... The value to search for. ... Zero-based index at which to start searching, converted to an integer. Negative index counts back from the end of the array — if -array.length <= fromIndex < 0, fromIndex + array.length is used.
🌐
CodePen
codepen.io › garethredfern › pen › YzPEqoo
Filter Array of Objects by Array of Exclude Property Values Vanilla JS
Use the built in JavaScript includes method to filter an array of objects by another array of properties you wish to exclude....