I have two arrays. In each array I have objects with lots of properties but no methods. I need to see if array 1 is equal with array 2.
One way to do that would be t
Converting your arrays to strings and then comparing the strings will have the same average and worst performance: O(n) (linear).
If you loop through your objects properties/arrays and abort on the 1st mismatch your worst performance will still be O(n) but your average performance might significantly improve unless the objects your'e comparing are usually identical. Either way, since this traversal wouldn't include creating any new objects and copying bytes around - even comparing identical composite objects/arrays (worst case) should still be faster than stringifying them.
As this answer suggests you could just use Underscore.js isEqual:
which according to docs: Performs an optimized deep comparison between the two objects, to determine if they should be considered equal
I'm pretty sure it will work for arrays too.