I am trying to compare two arrays and display the values that do not match.
Using jQuery, I have this:
$.each(array1, function(key, value)
{
var index = $.inArray(value, array2);
if(index != -1)
{
console.log(index);
}
});
Using the above code, I can find the array elements that match.
For example, the array1 looks like this:
"GESU687543", "TCNU315504", "TGHU394463"
array2 looks like this:
"TCNU315504", "TRIU805499", "CMAU029901", "GESU687543", "TGHU394463", "NEUL0325B"
But the console will only display 3, 0, 4 because those values exist in both arrays. I want to do the exact opposite. I need to find the values that don't match and display those values to the page.
So, using my examples above, the values that should be displayed to the console are:
"TRIU805499", "CMAU029901", "NEUL0325B"
Edit
SO advised me that this question is possibly a duplicate: How to get the difference between two arrays in Javascript?
With that said, that page is using JavaScript. I'm strictly using jQuery here.