Skip to content

Instantly share code, notes, and snippets.

@samueleaton
Last active February 6, 2016 20:58
Show Gist options
  • Save samueleaton/049e196db755ae542c2b to your computer and use it in GitHub Desktop.
Save samueleaton/049e196db755ae542c2b to your computer and use it in GitHub Desktop.
// es5
function isArray(obj) {
if(typeof obj === 'object' && ((Array.isArray && Array.isArray(obj)) ||
obj.constructor === Array ||
obj instanceof Array)) {
return true;
}
return false;
}
// es2015
const isArray = obj => typeof obj === 'object' && ((Array.isArray && Array.isArray(obj)) || obj.constructor === Array || obj instanceof Array);
@samueleaton
Copy link
Author

isArray(1); // false
isArray('array'); // false
isArray({}); // false
isArray([]); // true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment