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.
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' ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With