Y
Hacker News
new
|
ask
|
show
|
jobs
by
hcarvalhoalves
4635 days ago
Last one reminded me how awful JS is once again. There are 5 different ways to check if an object is an array, some are implementation dependent, and the obvious one doesn't work (typeof x == "array").
2 comments
hayksaakian
4635 days ago
typeof(x) === typeof(["something which is certainly", "an array"])
or am i missing something?
link
wging
4635 days ago
> typeof ["a", "b"] "object"
Of course, since you're told you'll only get numbers, arrays, and strings, that is enough to solve the problem narrowly.
link
Bahamut
4635 days ago
x instanceof Array
link
or am i missing something?