#Difference between 2 arrays

5 messages · Page 1 of 1 (latest)

obtuse frigate
#

Hey guys, is there a way to check difference between 2 arrays?

For example:
Array1 = [1,2,3,4,5]
Array2 = [1,3,5]
Difference = [2,4]

west jewel
#

const difference = Array1.filter(e => !Array2.includes(e))

#

For this to work, you'd have to know which array is larger btw

#

If you switch Array1 and array2 around, difference would be an empty array

#

I mean, I guess you can switch it around for both and then concat the two differences, might be a better way though