Skip to content

Instantly share code, notes, and snippets.

@bjdixon bjdixon/is_array.js
Last active Aug 29, 2015

What would you like to do?
Check if value is an array or not in javascript
// typeof operator reports arrays as 'object'
// this function can be used to determine if the value is an array or not.
var is_array = function (value) {
return Object.prototype.toString.apply(value) === '[object Array]';
var ar1 = ['abc', 'def', 'hij']; // array
var ob1 = {'0': 'abc', '1': 'def', '2': 'hij'}; // object
var va1 = 'abcdefhij'; // string
console.log(is_array(ar1)); // true
console.log(is_array(ob1)); // false
console.log(is_array(va1)); // false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.