Array.includes(val) returns false

array = [[0, 1],
         [2, 3],
         [4, 5],
         [5, 6]];

console.log(array.includes([0, 1])); **//prints false but why?**

console.log(array.includes(array[0])); //prints true

It’s because of the comparison algorithm that .includes() uses.

Since Array is an object, you can’t use == or === to compare the content of the arrays:

[0,1] === [0,1]; // false

When you compare two arrays with the operator, JavaScript actually compares whether the objects are the same.

let myArray = [1,2,3];
let anotherArray = myArray;

myArray === anotherArray; // true

You’d need to come up with another way of validating if that array is nested…

1 Like