Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
310 views
in Technique[技术] by (71.8m points)

javascript - 如何在JavaScript中比较数组?(How to compare arrays in JavaScript?)

I'd like to compare two arrays... ideally, efficiently.(我想比较两个数组...理想地,有效地比较。)

Nothing fancy, just true if they are identical, and false if not.(没有幻想,如果相同则为true ,否则为false 。) Not surprisingly, the comparison operator doesn't seem to work.(毫不奇怪,比较运算符似乎不起作用。) 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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

Please log in or register to answer this question.

Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...