Unless they are the same array instance, comparing the memory locations won't work in JavaScript (what happens when you do arr1 == arr2
).
You would need to explicitly loop.
Some people use JSON.stringify()
(watch out for the gotcha explained in the comments by pimvdb) on both arrays and compare the resulting strings to cheat, but serialising to a string and comparing sounds over fully expensive to me. However it works, so if there is no performance problem, go nuts! :)
You could also try toSource()
.
I would build my own comparative function that compares just enough that satisfies my idea of identical.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…