Semantics, [1, 2] and [2, 1] have the same entries but aren't the same arrays.
You're right, if you wanted to know if they have the same entries in the same order you wouldn't sort them.
It's just creating two JSON strings and compares them, all of JSONs limitations (not only undefined or null but also Infinite, NaN, functions, symbols and such) apply. Shouldn't have to mention it as should be fairly obvious.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Why do sort though? Those are not the same arrays
[1, 2]
,[2, 1]
.Semantics,
[1, 2]
and[2, 1]
have the same entries but aren't the same arrays.You're right, if you wanted to know if they have the same entries in the same order you wouldn't sort them.
JSON.stringify([undefined]) === JSON.stringify([null])
It's just creating two JSON strings and compares them, all of JSONs limitations (not only
undefined
ornull
but alsoInfinite
,NaN
, functions, symbols and such) apply. Shouldn't have to mention it as should be fairly obvious.