Home Ask Login Register

Developers Planet

Your answer is one click away!

Rishav February 2016

Coffeescript `in` operator doesn't work with 2D array

Checking for values in 1D arrays works..

coffee> 1 in [1,2]


coffee> [1, 1] in [[1, 1], [1, 2]]

Checking for values in 2D arrays doesn't.

Am I missing something, is this a bug or is this intended?


tyler February 2016

Javascript does not count two "equal" arrays as equal

[1,1] === [1,1]
--> false
[1,1] == [1,1]
--> false

So it would be counterintuitive for coffeescript to do what you're proposing.

You could write your own method to do the comparison, or you could use something like Lodash's isEqual() method https://lodash.com/docs#isEqual

Post Status

Asked in February 2016
Viewed 2,531 times
Voted 14
Answered 1 times


Leave an answer

Quote of the day: live life