Skip to content

Instantly share code, notes, and snippets.

@atikju
Last active October 24, 2018 13:07
Show Gist options
  • Save atikju/89837582341e151a6a1696370f3d6b7e to your computer and use it in GitHub Desktop.
Save atikju/89837582341e151a6a1696370f3d6b7e to your computer and use it in GitHub Desktop.
JS - compare two arrays and find the mismatched elements
var current = [1, 2, 3, 4, 7, 8],
prev = [1, 2, 4],
isMatch = false,
missing = null;
var i = 0, y = 0,
lenC = current.length,
lenP = prev.length;
for ( ; i < lenC; i++ ) {
isMatch = false;
for ( y = 0; y < lenP; y++ ) {
if (current[i] == prev[y]) isMatch = true;
}
if ( !isMatch ){
missing = current[i];
alert(missing);
} // Current[i] isn't in prev
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment