Why does the following line return false
in Javascript:
[[1,2,3], [1,2,4]].includes([1,2,3]);
What is the underlying logic behind that?
See Question&Answers more detail:osWhy does the following line return false
in Javascript:
[[1,2,3], [1,2,4]].includes([1,2,3]);
What is the underlying logic behind that?
See Question&Answers more detail:osincludes
compares using SameValueZero equality algorithm. (As mentioned in developer.mozilla.org). When searching for objects (array is object as well), it will match only references to the same object.
Additionally, Javascript arrays are objects and you can't simply use the equality operator ==
to understand if the content of those objects is the same. The equality operator will only test if two object are actually exactly the same instance (e.g. myObjVariable==myObjVariable
, works for null
and undefined
too).