OneCompiler

[JavaScript] How to get difference between two arrays?

I want to find the difference between two arrays, how to do that in Javascript?

1 Answer

4 years ago by

You can use either of the below approaches to get the difference between two arrays:

Method: 1

arr1.filter(ele => arr2.indexOf(ele) === -1)

Method: 2

arr1.filter(ele => !arr2.includes(ele))

Run here https://onecompiler.com/javascript/3xn788gvt

4 years ago by Meera