var a = [1,2,3]
var b = a.sort();
console.log('a',a,'b',b); // a [1,2,3] b [1,2,3]
console.log(a === b); // true
a = [1,3,2];
console.log(a.sort() === b) // false
console.log('a',a,'b',b); // a [1,2,3] b [1,2,3]
console.log(a === b) // false
My questions are - why? [I'm getting 2x false.] And additional one - it's possible to have original array untouched, maybe some parameter or other sorting function?
I mean:
var a = [1,3,2];
var b = a.SomeOtherSortFn();
console.log('a',a,'b',b); // a [1,3,2] b [1,2,3]
Edit: My goal wasn't to check if arrays are equal. Compare length, loop through values - no big deal. My question is - why arrays identical in the first place aren't identical in the second one.
I got my answer, thank you Arun Ghosh.