Last active
December 9, 2017 23:36
-
-
Save Nicknyr/3dc9ccb7129272bf8dc0f76c712f5906 to your computer and use it in GitHub Desktop.
Javascript: Use .every() function to compare two arrays and determine if they have the same elements in the same order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Compare two arrays and determine if they have the same values in the same order | |
var compare = arr1.length == arr2.length && | |
arr1.every(function(element, index){ | |
return element == arr2[index]; | |
}); | |
if(compare) { | |
// Arrays match, do this | |
} | |
else { | |
// Arrays don't match, do this | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is this intended behavior? If not, consider using
===
insideevery
function.