Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the difference of arrays in ES6?

Tags:

People also ask

How do I compare two arrays of arrays?

Using Arrays. equals(array1, array2) methods − This method iterates over each value of an array and compare using equals method. Using Arrays. deepEquals(array1, array2) methods − This method iterates over each value of an array and deep compare using any overridden equals method.

How do I compare to arrays JavaScript?

While JavaScript does not have an inbuilt method to directly compare two arrays, it does have inbuilt methods to compare two strings. Strings can also be compared using the equality operator. Therefore, we can convert the arrays to strings, using the Array join() method, and then check if the strings are equal.


So I have two arrays:

const allLanguages = [ 'ES', 'EN', 'DE' ] const usedLanguages = [ { id: 1, lang: 'EN' } ] 

What's the quickest way to produce a new array which is the difference between these two? In old school JavaScript, you'd have to do a for loop inside another for loop, I think...

Eg:

const availableLanguages = [ 'ES', 'DE' ]