What's the fastest/best way to compare two arrays and return the difference? Much like array_diff
in PHP. Is there an easy function or am I going to have to create one via each()
? or a foreach
loop?
In Java, we can compare two arrays by comparing each element of the array. Java Arrays class provides two predefined methods that is used to compare two arrays in Java. In this section, we will learn how to compare two Arrays using Arrays. equals() method and Arrays.
I know this is an old question, but I thought I would share this little trick.
var diff = $(old_array).not(new_array).get();
diff
now contains what was in old_array
that is not in new_array
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