There are two arrays in JavaScript, they are both in the following format:
[{\'drink\':[\'alcohol\', \'soft\', \'hot\']}, {\'fruit\':[\'apple\', \'pear\']}];
With Javascript, you can't check if arrays are equals, but you can compare them like this:
var arr1 = ['alcohol', 'soft', 'hot'],
arr2 = ['apple', 'pear'],
arr3 = ['soft', 'hot', 'alcohol'];
function isSame(a1, a2){
return !(a1.sort() > a2.sort() || a1.sort() < a2.sort());
}
console.log( isSame(arr1, arr2) ); //false
console.log( isSame(arr1, arr3) ); //true
The sort
put all elements in the same order, and if both <
and >
comparisons are false it means both are the same.