Distinguish between array and hash in javascript with typeof()

Viewed 7828

Possible Duplicate:
In javascript how can we identify whether an object is a Hash or an Array?

In javascript

typeof([])

and

typeof({})

both return "object".

How can I reliably distinguish between an array and an associative array in Javascript?

I have thought of testing the object in question to see if it has the "length" attribute (indicating it would be an array), but what then the following would also be seen as an array:

{length:5}
3 Answers
Related