Detect if parameter passed is an array? Javascript

Alex picture Alex · May 4, 2010 · Viewed 26.6k times · Source

Possible Duplicate:
How to detect if a variable is an array

I have a simple question:

How do I detect if a parameter passed to my javascript function is an array? I don't believe that I can test:

if (typeof paramThatCouldBeArray == 'array') 

So is it possible?

How would I do it?

Thanks in advance.

Answer

Casey Chu picture Casey Chu · May 4, 2010
if (param instanceof Array)
    ...

Edit. As of 2016, there is a ready-built method that catches more corner cases, Array.isArray, used as follows:

if (Array.isArray(param))
    ...