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

typeof(x) === typeof(["something which is certainly", "an array"])

or am i missing something?

     > 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.
x instanceof Array