The method given in the ECMAScript standard to find the class of Object is to use the toString method from Object.prototype.

if(Object.prototype.toString.call(someVar) === '[object Array]') {
    alert('Array!');
}

Or you could use typeof to test if it is a string:

if(typeof someVar === 'string') {
    someVar = [someVar];
}

Or if you're not concerned about performance, you could just do a concat to a new empty Array.

someVar = [].concat(someVar);

There's also the constructor which you can query directly:

if (somevar.constructor.name == "Array") {
    // do something
}

Check out a thorough treatment from T.J. Crowder's blog, as posted in his comment below.

Check out this benchmark to get an idea which method performs better: http://jsben.ch/#/QgYAV

From @Bharath, convert a string to an array using ES6 for the question asked:

const convertStringToArray = (object) => {
   return (typeof object === 'string') ? Array(object) : object
}

Suppose:

let m = 'bla'
let n = ['bla','Meow']
let y = convertStringToArray(m)
let z = convertStringToArray(n)
console.log('check y: '+JSON.stringify(y)) . // check y: ['bla']
console.log('check y: '+JSON.stringify(z)) . // check y: ['bla','Meow']
Answer from user113716 on Stack Overflow
🌐
W3Schools
w3schools.com › Js › js_typeof.asp
JavaScript typeof
You cannot use typeof to determine if a JavaScript object is an array or a date.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › isArray
Array.isArray() - JavaScript | MDN
Array.isArray() accepts Array objects constructed in another realm — instanceof Array returns false for these because the identity of the Array constructor is different across realms. See the article "Determining with absolute accuracy whether or not a JavaScript object is an array" for more details.
Top answer
1 of 16
2068

The method given in the ECMAScript standard to find the class of Object is to use the toString method from Object.prototype.

if(Object.prototype.toString.call(someVar) === '[object Array]') {
    alert('Array!');
}

Or you could use typeof to test if it is a string:

if(typeof someVar === 'string') {
    someVar = [someVar];
}

Or if you're not concerned about performance, you could just do a concat to a new empty Array.

someVar = [].concat(someVar);

There's also the constructor which you can query directly:

if (somevar.constructor.name == "Array") {
    // do something
}

Check out a thorough treatment from T.J. Crowder's blog, as posted in his comment below.

Check out this benchmark to get an idea which method performs better: http://jsben.ch/#/QgYAV

From @Bharath, convert a string to an array using ES6 for the question asked:

const convertStringToArray = (object) => {
   return (typeof object === 'string') ? Array(object) : object
}

Suppose:

let m = 'bla'
let n = ['bla','Meow']
let y = convertStringToArray(m)
let z = convertStringToArray(n)
console.log('check y: '+JSON.stringify(y)) . // check y: ['bla']
console.log('check y: '+JSON.stringify(z)) . // check y: ['bla','Meow']
2 of 16
1616

In modern browsers you can do:

Array.isArray(obj)

(Supported by Chrome 5, Firefox 4.0, Internet Explorer 9, Opera 10.5 and Safari 5)

For backward compatibility you can add the following:

// Only implement if no native implementation is available
if (typeof Array.isArray === 'undefined') {
  Array.isArray = function(obj) {
    return Object.prototype.toString.call(obj) === '[object Array]';
  }
};

If you use jQuery you can use jQuery.isArray(obj) or $.isArray(obj). If you use Underscore.js you can use _.isArray(obj).

If you don't need to detect arrays created in different frames you can also just use instanceof:

obj instanceof Array
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › some
Array.prototype.some() - JavaScript | MDN
February 24, 2026 - const arrayLike = { length: 3, 0: "a", 1: "b", 2: "c", 3: 3, // ignored by some() since length is 3 }; console.log(Array.prototype.some.call(arrayLike, (x) => typeof x === "number")); // false · Polyfill of Array.prototype.some in core-js · es-shims polyfill of Array.prototype.some ·
🌐
Quora
quora.com › Why-is-a-type-typeof-array-in-JavaScript-object-not-an-array-JavaScript-arrays-object-typeof-development
Why is a type typeof (array) in JavaScript object not an array (JavaScript, arrays, object, typeof, development)? - Quora
Answer: JavaScript currently has ... types: [code ]"undefined"[/code], "[code ]boolean"[/code], "[code ]string"[/code], "[code ]number"[/code], "[code ]bigint"[/code], "[code ]symbol"[/code], "[code ]function"[/code], and "[code ]object"[/code]. Of these, ...
🌐
C# Corner
c-sharpcorner.com › article › identify-if-a-variable-is-an-array-or-object-in-javascript
Identify If A Variable Is An Array Or Object In JavaScript
October 26, 2020 - JavaScript arrays are objects. If you execute the code below, it will return an object as its type. ... console.log(typeof(pizza)); OK, that’s weird. If an array is an object; therefore, JavaScript arrays can have string keys/properties added to them. The answer is yes.
🌐
Built In
builtin.com › software-engineering-perspectives › javascript-array-typeof
JavaScript Typeof for Data Types: Array, Boolean and More | Built In
As long as the value in question ... is built into JavaScript is the array, and the typeof of an array is "object": typeof [] === `object` // true....
Find elsewhere
🌐
Reddit
reddit.com › r/learnjavascript › how to determine if a variable is an array - mastering js
r/learnjavascript on Reddit: How to Determine if a Variable is an Array - Mastering JS
May 14, 2021 - Key takeaway from this tutorial is don't use `typeof` because that doesn't work. `instanceof Array` is another option that should work. ... Just started learning JavaScript so is this 22hrs long video by super simple dev worth it or shall I move out to other resources ( paid or free on internet ...
Top answer
1 of 16
2068

There are several ways of checking if an variable is an array or not. The best solution is the one you have chosen.

variable.constructor === Array

This is the fastest method on Chrome, and most likely all other browsers. All arrays are objects, so checking the constructor property is a fast process for JavaScript engines.

If you are having issues with finding out if an objects property is an array, you must first check if the property is there.

variable.prop && variable.prop.constructor === Array

Some other ways are:

Array.isArray(variable)

Update May 23, 2019 using Chrome 75, shout out to @AnduAndrici for having me revisit this with his question This last one is, in my opinion the ugliest, and it is one of the slowest fastest. Running about 1/5 the speed as the first example. This guy is about 2-5% slower, but it's pretty hard to tell. Solid to use! Quite impressed by the outcome. Array.prototype, is actually an array. you can read more about it here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray

variable instanceof Array

This method runs about 1/3 the speed as the first example. Still pretty solid, looks cleaner, if you're all about pretty code and not so much on performance. Note that checking for numbers does not work as variable instanceof Number always returns false. Update: instanceof now goes 2/3 the speed!

So yet another update

Object.prototype.toString.call(variable) === '[object Array]';

This guy is the slowest for trying to check for an Array. However, this is a one stop shop for any type you're looking for. However, since you're looking for an array, just use the fastest method above.

Also, I ran some test: http://jsperf.com/instanceof-array-vs-array-isarray/35 So have some fun and check it out.

Note: @EscapeNetscape has created another test as jsperf.com is down. http://jsben.ch/#/QgYAV I wanted to make sure the original link stay for whenever jsperf comes back online.

2 of 16
1198

You could also use:

if (value instanceof Array) {
  alert('value is Array!');
} else {
  alert('Not an array');
}

This seems to me a pretty elegant solution, but to each his own.

Edit:

As of ES5 there is now also:

Array.isArray(value);

But this will break on older browsers, unless you are using polyfills (basically... IE8 or similar).

🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-arrays
JavaScript Arrays - GeeksforGeeks
Arrays can hold any type of data-such as numbers, strings, objects, or even other arrays—making them a flexible and essential part of JavaScript programming.
Published   October 3, 2025
🌐
Go Make Things
gomakethings.com › how-to-check-if-an-object-is-an-array-with-vanilla-javascript
How to check if an object is an array with vanilla JavaScript | Go Make Things
April 3, 2018 - However, this doesn’t work with arrays. It returns object, just like objects, dates, and more. // Returns 'object' typeof ['tuna', 'chicken', 'pb&j']; // Also returns 'object' typeof {sandwich: 'tuna', chips: 'cape code'}; Todd Motto showed me an interesting way to deal with this: the Object.prototype.toString() method. This method converts the object type into a string. And in JavaScript, confusingly, everything is an object—not just proper objects ({}).
🌐
Proto Coders Point
protocoderspoint.com › home › scripting languages › javascript – check whether a variable type is an array or not
JavaScript - Check whether a variable type is an array or not
January 2, 2023 - const arrData = [4,3,1,5,6,7,3,1]; console.log(arrData) console.log(typeof arrData); // object console.log(Array.isArray(arrData)); // true
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › typeof
typeof - JavaScript | MDN
(logical NOT) operator are equivalent to Boolean() // Symbols typeof Symbol() === "symbol"; typeof Symbol("foo") === "symbol"; typeof Symbol.iterator === "symbol"; // Undefined typeof undefined === "undefined"; typeof declaredButUndefinedVariable === "undefined"; typeof undeclaredVariable === "undefined"; // Objects typeof { a: 1 } === "object"; // use Array.isArray or Object.prototype.toString.call // to differentiate regular objects from arrays typeof [1, 2, 4] === "object"; typeof new Date() === "object"; typeof /regex/ === "object"; // The following are confusing, dangerous, and wasteful.
🌐
Attacomsian
attacomsian.com › blog › javascript-check-if-object-is-array
How to check if an object is an array in JavaScript
June 13, 2020 - You may have used the typeof operator in JavaScript to check the type of an object. But, unfortunately, it doesn't work for arrays.
🌐
Medium
medium.com › dailyjs › how-to-check-if-variable-is-an-array-in-javascript-1f7ddc0f180f
How to check if Variable is an Array in JavaScript | by Samantha Ming | DailyJS | Medium
May 13, 2020 - if (!Array.isArray) { Array.isArray = function(arg) { return Object.prototype.toString.call(arg) === '[object Array]'; }; } ... JavaScript news and opinion.
🌐
DEV Community
dev.to › pestrinmarco › typeof-array-is-an-object-in-javascript-1p6k
Typeof array is an object in javascript - DEV Community
March 3, 2021 - const arr = [2,4,6,8] const obj = { type: ‘serviceBot’, valid: true } console.log(typeof arr) console.log(typeof obj) ... Apparently there seems to be something wrong because the array is recognized as an object and seems to be no real difference between object and array. This because in javascript all derived data type is always a type object.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-check-object-is-an-array-in-javascript
How to Check Object is an Array in JavaScript? - GeeksforGeeks
November 17, 2024 - The instanceof operator tests whether an object is an instance of a specific constructor (in this case, Array). This approach is particularly useful because it checks the prototype chain to determine if an object is derived from Array.