I'd like to compare two arrays... ideally, efficiently.
(我想比较两个数组...理想地,有效地比较。)
Nothing fancy, justtrue
if they are identical, and false
if not. (没有幻想,如果相同则为true
,否则为false
。)
(毫不奇怪,比较运算符似乎不起作用。)
var a1 = [1,2,3];
var a2 = [1,2,3];
console.log(a1==a2); // Returns false
console.log(JSON.stringify(a1)==JSON.stringify(a2)); // Returns true
JSON encoding each array does, but is there a faster or "better" way to simply compare arrays without having to iterate through each value?
(每个数组都可以使用JSON编码,但是有没有一种更快或更“更好”的方法来简单地比较数组而不必遍历每个值?)
ask by Julian H. Lam translate from so