0
var coords = [
    [0,0],[5,0],[0,5],[5,5],[8,5],[8,0],[40,5],[5,54],[6,7],[40,0],[8,54]
]
console.log(coords.includes([0,0]))

The result here is false, and I am unsure why. Please help

1

1 Answer 1

1

Array.prototype.includes compares the values using the strictly equal operator. Arrays are stored by reference and not by value. [] === [] will never be true, unless you are comparing the same array stored in your array.

A way to solve this issue is using Array.prototype.some

var coords = [
    [0,0],[5,0],[0,5],[5,5],[8,5],[8,0],[40,5],[5,54],[6,7],[40,0],[8,54]
]
console.log(coords.some(coordinate => {
const [x, y] = coordinate
// This is the value you are comparing
const myCoords = [0, 0]
return x === myCoords[0] && y === myCoords[1]
}))

Sign up to request clarification or add additional context in comments.

1 Comment

Awesome thanks so much.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.