I would do as follows;

var arr1 = [1,2,3,4],
    arr2 = [2,4],
    res = arr1.filter(item => !arr2.includes(item));
console.log(res);

Answer from Redu 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 array argument is useful if you want to access another element in the array, especially when you don't have an existing variable that refers to the array. The following example first uses map() to extract the numerical ID from each name and then uses filter() to select the ones that are greater than its neighbors.
🌐
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.
🌐
Built In
builtin.com › software-engineering-perspectives › javascript-filter
How to Filter a JavaScript Array With the Filter() Method | Built In
The filter() method is also called ... original array. The JavaScript array filter() method allows you to filter an array to only see elements that meet a specified condition....
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript array methods › array.prototype.filter()
JavaScript Array filter() Method
November 7, 2024 - This tutorial shows you how to use the JavaScript array filter() method to filter elements in an array based on a specified condition.
🌐
freeCodeCamp
freecodecamp.org › news › filter-arrays-in-javascript
How to Filter an Array in JavaScript – JS Filtering for Arrays and Objects
November 7, 2024 - There is more to filtering arrays in JavaScript with the JavaScript filter() method.
🌐
LogRocket
blog.logrocket.com › home › how to use the array filter() method in javascript
How to use the array filter() method in JavaScript - LogRocket Blog
March 24, 2025 - Before diving into chaining, let’s quickly review how these methods work individually: filter() – Narrows down the array by selecting only elements that meet a specific condition
🌐
freeCodeCamp
freecodecamp.org › news › javascript-array-filter-tutorial-how-to-iterate-through-elements-in-an-array
JavaScript Array.filter() Tutorial – How to Iterate Through Elements in an Array
October 15, 2024 - The Array.filter() method is arguably the most important and widely used method for iterating over an array in JavaScript. The way the filter() method works is very simple. It entails filtering out one or more items (a subset) from a larger collectio...
Find elsewhere
🌐
Simplilearn
simplilearn.com › home › resources › software development › javascript tutorial: learn javascript from scratch › how to use javascript array filter(): explained with examples
How to Use JavaScript Array Filter() With Examples | Simplilearn
August 11, 2025 - The JavaScript Array Filter() filters out the elements of an array based on the specified test condition. Read on to know the syntax and parameter values, how it works with example and the limitations.
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
Codecademy
codecademy.com › docs › javascript › arrays › .filter()
JavaScript | Arrays | .filter() | Codecademy
July 29, 2025 - .filter() returns an array of all matching elements, while .find() returns only the first matching element or undefined if no match is found. ... Front-end engineers work closely with designers to make websites beautiful, functional, and fast.
🌐
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.
🌐
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.

🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › filter-array-of-objects
Filter an Array of Objects in JavaScript - Mastering JS
A filter callback can be arbitrarily sophisticated, as long as it is synchronous. For example, suppose you have a list of Star Trek characters, and you want to get just the characters that appeared in Star Trek: The Next Generation. Here's how you can use Array#filter() to filter an array of characters given that the series property is an array:
🌐
Flexiple
flexiple.com › javascript › javascript-filter-array
How to use the JavaScript filter array method? - Flexiple Tutorials - Flexiple
A function or search criteria that would be used to filter values in the array · value - Required, the current element that needs to be filtered · index - Optional, in case you would like to start the iteration from a specific index ... We have all used filters on websites as they help us find things easily, the JavaScript filter array function is what facilitates this.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript-array-filter-method
JavaScript Array filter() Method | GeeksforGeeks
January 10, 2025 - Example 2: Creating a new array consisting of only those elements that satisfy the condition checked by isEven() function. ... function isEven(value) { return value % 2 == 0; } let filtered = [11, 98, 31, 23, 944].filter(isEven); console.log(filtered); ... We have a complete list of Javascript Array methods, to check those please go through this Javascript Array Complete reference article.
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
);
🌐
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.
🌐
Go Make Things
gomakethings.com › how-to-filter-items-in-an-array-with-vanilla-javascript
How to filter items in an array with vanilla JavaScript | Go Make Things
You call the Array.filter() method on an array, and pass in a callback function that accepts three arguments: the current item in the loop, its index, and the array itself.
🌐
Vultr Docs
docs.vultr.com › javascript › standard-library › Array › filter
JavaScript Array filter() - Filter Array Elements | Vultr Docs
November 28, 2024 - Define an array with various elements. Apply the filter() method to create a new array that excludes certain elements based on a condition.