🌐
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 filter() method of Array instances creates a shallow copy of a portion of a given array, filtered down to just the elements from the given array that pass the test implemented by the provided function.
🌐
W3Schools
w3schools.com › jsref › jsref_filter.asp
JavaScript Array filter() Method
The filter() method creates a new array filled with elements that pass a test provided by a function.
🌐
Reddit
reddit.com › r/learnjavascript › filtering an array javascript and keeping unfiltered items in another array
r/learnjavascript on Reddit: Filtering an array JavaScript and keeping unfiltered items in another array
November 14, 2021 -

I have an array of numbers ex:

const array = [4, 9, 1, 3, 5, 4, 0, 4, 6, 3, 0, 7, 2, 5, 2, 3]

and I want to filter every other number into two separate arrays. I want one array to start at index 0 and another to start at index 1. So in this example, it would be:

x = [4, 1, 5, 0, 6..... etc]

y = [9, 3, 4, 4, 3....etc]

I know about the .filter method and I was hoping to use this, but I am not good enough at loops yet to figure out how to do every other item. I have been stuck on this for a while and it would be great if someone could help me out.

🌐
Mike Bifulco
mikebifulco.com › home › javascript tips: using array.filter(boolean)
JavaScript Tips: Using Array.filter(Boolean) | Mike Bifulco
November 12, 2021 - We're using a function built into arrays in JavaScript, called Array.prototype.filter, which creates a new array containing all elements that pass the check within the function it takes as an argument.
🌐
Programiz
programiz.com › javascript › library › array › filter
Javascript Array filter()
Returns a new array with only the elements that passed the test. ... const prices = [1800, 2000, null, 3000, 5000, "Thousand", 500, 8000] function checkPrice(element) { return element > 2000 && !Number.isNaN(element); } let filteredPrices = prices.filter(checkPrice); console.log(filteredPrices); ...
🌐
Tabnine
tabnine.com › home › how to use the array filter() method in javascript
How to Use the Array filter() method in JavaScript - Tabnine
July 25, 2024 - The filter() method filters an array according to provided criteria, returning a new array containing the filtered items. The Array object’s filter() method is an iteration method which enables us to retrieve all of an array’s elements that ...
🌐
Ultimate Courses
ultimatecourses.com › blog › array-filter-javascript
Exploring Array Filter in JavaScript - Ultimate Courses
March 25, 2020 - Array Filter expects us to return an expression that will evaluate true or false, we can go straight to the finish line and make it easier by supplying literally true and false array values. I’m using JavaScript’s Boolean object to coerce the array element to a Boolean.
Find elsewhere
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
How to filter an array with another array - JavaScript - The freeCodeCamp Forum
August 1, 2017 - I have done a bit of research on this topic, but I am still confused about the best way to filter an array with another array. There are two scenarios I would like to understand better. (1) The second array remains intact after filtering the first array. For example: Input: array1 = [a, b, ...
🌐
GitHub
github.com › zloirock › core-js
GitHub - zloirock/core-js: Standard Library · GitHub
import 'core-js/actual'; Promise.try(() => 42).then(it => console.log(it)); // => 42 Array.from(new Set([1, 2, 3]).union(new Set([3, 4, 5]))); // => [1, 2, 3, 4, 5] [1, 2].flatMap(it => [it, it]); // => [1, 1, 2, 2] Iterator.concat([1, 2], function * (i) { while (true) yield i++; }(3)) .drop(1).take(5) .filter(it => it % 2) .map(it => it ** 2) .toArray(); // => [9, 25] structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])
Author   zloirock
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
);
🌐
Favtutor
favtutor.com › articles › javascript-array-filter
JavaScript Array Filter() Method (with Examples)
November 8, 2023 - The filter() function is a powerful array method in JavaScript that allows one to create a new array containing elements that satisfy a specific condition.
🌐
Fjolt
fjolt.com › article › javascript-filter
Javascript Array Filter Method
October 17, 2022 - The filter method in Javascript creates a shallow copy of an array, filtering it based on a number of conditions. It accepts a callback function. The array which filter produces will usually be a reduced version of the original array.
🌐
Codecademy
codecademy.com › docs › javascript › arrays › .filter()
JavaScript | Arrays | .filter() | Codecademy
July 29, 2025 - JavaScript’s array.filter() method creates a new array containing only the elements from the original array that pass a test implemented by a provided function.
🌐
Anton Dev Tips
antondevtips.com › blog › how-to-filter-arrays-in-javascript-a-comprehensive-guide
How to Filter Arrays in JavaScript: A Comprehensive Guide
Array filtering in JavaScript allows you to create a new array from an existing one, containing only elements that match a given condition.
🌐
DEV Community
dev.to › ivanadokic › javascript-array-methods-filter-map-reduce-and-sort-32m5
JavaScript Array methods: Filter, Map, Reduce, and Sort - DEV Community
April 2, 2021 - Follows the examples of how to use it. filter() returns a new array of filter elements that meet a certain condition. The filter() method creates a new array with all elements that pass the test implemented by the provided function.
🌐
React
react.dev › learn › rendering-lists
Rendering Lists – React
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).
🌐
jsonworld
jsonworld.com › blog › filter-array-in-javascript
Filter Array in Javascript | JSON World
April 14, 2020 - filter() creates a new array with filtered elements that lie under specific conditions.
🌐
daily.dev
daily.dev › home › blog › get into tech › filter arrays in javascript: a primer
Filter Arrays in JavaScript: A Primer
December 22, 2025 - Learn how to efficiently filter arrays in JavaScript using the filter() method. Explore real-world examples and combine filter() with other array methods for advanced data handling.