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
December 13, 2025 - function isBigEnough(value) { return value >= 10; } const filtered = [12, 5, 8, 130, 44].filter(isBigEnough); // filtered is [12, 130, 44] The following example returns all prime numbers in the array:
๐ŸŒ
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.
Discussions

javascript - How to filter an array from all elements of another array - Stack Overflow
I'd like to understand the best way to filter an array from all elements of another one. I tried with the filter function, but it doesn't come to me how to give it the values i want to remove. Som... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Javascript array.filter() - can someone please give me an example of the use of 'thisArg'?
IIRC, it's just a way to automatically bind your callback function to a given object should you need to for whatever reason. Say you wanted pass an object function to your filter, like Database.prototype.findUserByEmail. You could bind that to an existing instance of Database, or pass that instance as the thisArg and let filter do the binding internally. More on reddit.com
๐ŸŒ r/learnprogramming
10
1
February 28, 2022
Best way to filter AND paginate a huge list of results?
You could look into using Datatables, it has an extension that allows you to load a large dataset and only renders what is required. http://datatables.net/extensions/scroller/ Edit: Just in case it's not obvious in this example, Datatables has filtering, sorting, pagination etc. It's just not enabled. This is an example of Datatables with default/zero configuration http://datatables.net/examples/basic_init/zero_configuration.html More on reddit.com
๐ŸŒ r/javascript
22
14
October 25, 2014
How to improve the performance of filtering an array that has 30k element?
I doubt it is the filtering itself that is particularly slow. About the only thing to optimize in your filter is to not call to Lower multiple times per item. Rather, what I think is likely the issue is that your ui doesn't handle the data well once you hit a certain number of items it tries to display. You should confirm this by testing the filtering of the items independently of the ui rendering those results. More on reddit.com
๐ŸŒ r/learnjavascript
33
11
June 1, 2023
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ javascript-filter-method
How the JavaScript Filter Method Works โ€“ Explained with Code Examples
February 15, 2024 - The filter method in JavaScript is designed as a higher-order function that iterates over each element of an array, allowing developers to apply a specific condition to filter out elements.
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ js-filter-array-method
How To Use the filter() Array Method in JavaScript | DigitalOcean
August 26, 2021 - An array with two values greater than 7 is returned. A common use case of filter() is with an array of objects through their properties.
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ javascript โ€บ filter
Master JavaScript Filter Operator: Apply Filter Arrays
The filter() method takes a callback function that defines the condition for filtering the array elements. The callback function is called for each element of the array, and elements that return true are kept, while others are excluded. ... Become a full-stack developer. Learn HTML, CSS, JavaScript, and React as well as NodeJS, Express, and SQL
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ javascript-array-filter-method
JavaScript Array filter() Method - GeeksforGeeks
// JavaScript to illustrate findIndex() ... elements pass the test. Example 1: Creating a new array consisting of only those elements that satisfy the condition checked by isPositive() function....
Published ย  January 10, 2025
Find elsewhere
๐ŸŒ
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 - This works because many JavaScript methods return an object, enabling consecutive method calls in a seamless flow. By chaining array methods, we can efficiently perform complex transformations while keeping the code concise and readable. 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
๐ŸŒ
JavaScript.info
javascript.info โ€บ tutorial โ€บ the javascript language โ€บ data types
Array methods
Write a function filterRangeInPlace(arr, a, b) that gets an array arr and removes from it all values except those that are between a and b.
๐ŸŒ
JavaScript Tutorial
javascripttutorial.net โ€บ home โ€บ javascript array methods โ€บ array.prototype.filter()
JavaScript Array filter() Method
November 7, 2024 - The following example uses the filter() method to return an array of numbers that are greater than 2: const numbers = [1, 3, 2, 7]; const results = numbers.filter((n) => n > 2); console.log({ results });Code language: JavaScript (javascript)
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ what-is-the-javascript-array-filter
What is the JavaScript Array filter()?
Here is the function signature ... in Javascript: ... As described above, the filter() function takes two inputs. function: A valid, pre-defined function. This can also be a lambda function. array: The array on which filter function is called. Returned: An array containing elements of the original array that satisfied all the conditions of the input function. Letโ€™s take a look at a couple of examples of how the ...
๐ŸŒ
daily.dev
daily.dev โ€บ home โ€บ blog โ€บ get into tech โ€บ filter arrays in javascript: a primer
Filter Arrays in JavaScript: A Primer
December 22, 2025 - What is filter()? A method to create a new array filled with elements that pass a test you define. How does it work? Write a function that returns true for items you want to keep, and false for those you don't. Real-world applications: From improving search functionality on websites to sorting through database results, filter() is incredibly versatile. Combine with other methods: Enhance its power by pairing filter() with map() and reduce() for more complex data handling.
๐ŸŒ
Mike Bifulco
mikebifulco.com โ€บ home โ€บ javascript tips: using array.filter(boolean)
JavaScript Tips: Using Array.filter(Boolean) | Mike Bifulco
November 12, 2021 - There's a subtle, but really important point here - Boolean() follows the JavaScript rules of truthiness. That means that the output Boolean() might not always be what you imagine. In this context, passing Boolean to .filter is effectively shorthand for doing this: ... I suspect that you may have seen at least one of these variations before. In the end, array.filter(Boolean) is just shorthand for any of the other options above.
๐ŸŒ
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 - Given this function above, letโ€™s break it apart into its components from the filter() prototype: The callback function in this code is getRecent. The currentValue is each sale in the parent array (sales). The array entries are provided in order, with each element being sent to getRecent in the parameter sale.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ filter-arrays-in-javascript
How to Filter an Array in JavaScript โ€“ JS Filtering for Arrays and Objects
November 7, 2024 - In this article, you have learned how to filter an array in JavaScript using the for loop and filter() method.
๐ŸŒ
Built In
builtin.com โ€บ software-engineering-perspectives โ€บ javascript-filter
How to Filter a JavaScript Array With the Filter() Method | Built In
Assign the new filtered array to a new variable. Here is an example that uses the filter() method to filter an array based on a search criteria for car brands that start with the letter โ€œB.โ€
๐ŸŒ
LeetCode
leetcode.com โ€บ problems โ€บ filter-elements-from-array โ€บ description
Filter Elements from Array - LeetCode
10; } Output: [20,30] Explanation: const newArray = filter(arr, fn); // [20, 30] The function filters out values that are not greater than 10 Example 2: Input: arr = [1,2,3], fn = function firstIndex(n, i) { return i === 0; } Output: [1] ...
๐ŸŒ
Flexiple
flexiple.com โ€บ javascript โ€บ javascript-filter-array
How to use the JavaScript filter array method? - Flexiple Tutorials - Flexiple
March 11, 2022 - We use the JavaScript filter array function to return freelancers containing the particular skillset. Furthermore, the JavaScript filter does not mutate the string but rather creates a new one hence the original string is not affected.
๐ŸŒ
Mastering JS
masteringjs.io โ€บ tutorials โ€บ fundamentals โ€บ array-filter
The JavaScript Array `filter()` Method - Mastering JS
The Array#filter() function in ... callback returns truthy for. For example, given an array of numbers 1-10, below is how you can use filter() to return an array of even numbers....
๐ŸŒ
Programiz
programiz.com โ€บ javascript โ€บ library โ€บ array โ€บ filter
Javascript Array filter()
// create a new array by filter even numbers from the numbers array let evenNumbers = numbers.filter(checkEven); console.log(evenNumbers); // Output: [ 2, 4, 6, 8, 10 ] ... Here, arr is an array.