Answer the question
In order to leave comments, you need to log in
How to quickly compare 2 numeric arrays?
Is it possible to somehow quickly compare numeric arrays:
arr1 = [1,2,3];
arr2 = [1,2,3];
arr3 = [3,2,1];
if(arr1 == arr2 || arr1 == arr3){
alert('correct');
}
else{alert('not right');}
Answer the question
In order to leave comments, you need to log in
the == operator does not compare arrays element by element, it compares references, and they are obviously different. The most common way to compare such small arrays is to cast them to a string using JSON.stringify() and compare the strings
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question