Skip to content

Instantly share code, notes, and snippets.

@iliadraznin
Created June 8, 2013 15:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iliadraznin/5735510 to your computer and use it in GitHub Desktop.
Save iliadraznin/5735510 to your computer and use it in GitHub Desktop.
Simple function to detect type Array. JavaScript return type "object" whether you give it an actual object like { red:44, green:57, blue:220 }, or an array like [44, 57, 220]. So I wrote this small function to separate the two.
function istype(obj) {
return (typeof obj !== 'object' || typeof obj[0] === 'undefined')
? typeof obj
: 'array';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment