Introduced in JavaScript 1.8.5
Summary
Returns true if an object is an array, false if it is not.
Method of the Array global object |
|
|---|---|
| Implemented in | JavaScript 1.8.5 |
| ECMAScript Edition | ECMAScript 5th Edition |
Syntax
Array.isArray(obj)
Parameters
- obj
- The object to be checked
Description
This function is part of the ECMAScript 5 standard. See the Web Tech Blog for more details.
Examples
// all following calls return true
Array.isArray([]);
Array.isArray([1]);
Array.isArray( new Array() );
Array.isArray( Array.prototype ); // Little known fact: Array.prototype itself is an array.
// all following calls return false
Array.isArray();
Array.isArray({});
Array.isArray(null);
Array.isArray(undefined);
Array.isArray(17);
Array.isArray("Array");
Array.isArray(true);
Array.isArray(false);
Array.isArray({ __proto__ : Array.prototype });
Compatibility
Running the following code before any other code will create Array.isArray if it's not natively available.
if(!Array.isArray) {
Array.isArray = function (vArg) {
return Object.prototype.toString.call(vArg) === "[object Array]";
};
}
Browser compatibility
Based on Kangax's compat table.
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | 5 | 4 (2.0) | 9 | 10.5 | 5 |
| Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | ? | ? | ? | ? | ? | ? |
See also
- Bug 510537 - ES5: Array.isArray
Mozilla Developer Network