WEBDOOD.COM

Archive for October, 2010

Javascript Array Detection

by webdood on Oct.06, 2010, under Javascript, Software Development

Turns out the most reliable way to detect an Array is not to use the old standby:

return (typeof foo === ‘object’ && foo.constructor === Array)

but rather to do this:

function isArray(anArray) {
  return Object.prototype.toString.apply(anArray) === "[object Array]";
}

I have to give credit to my friend Doug Crockford, for this.

I recommend his book Javascript: The Good Parts

shannon norrell

Leave a Comment :, , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...

  • A List Apart
  • Dive into HTML5
  • Javascript: The Good Parts
  • QuirksMode.org