Arrays are not identical after sorting even with identical values

前端 未结 2 1396
刺人心
刺人心 2021-01-29 13:38
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
         


        
2条回答
  •  不要未来只要你来
    2021-01-29 14:39

    When comparing two arrays the return value is true if they are referring to the same object. The values or the content of the arrays are not compared.

提交回复
热议问题