Table of contents
- 1. Summary
- 2. Syntax
- 3. Parameters
- 4. Description
- 5. Examples
- 6. Compatibility
- 7. Cross-browser compatibility
- 8. See also
Introduced in JavaScript 1.8.5
Summary
Returns true if an object is an array, false if it is not.
Method of 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);
Compatibility
Running the following code before any other code will create Array.isArray if it's not natively available. This relies on Object.prototype.toString being unchanged and call resolving to the native Function.prototype.call method.
if(!Array.isArray) {
Array.isArray = function (arg) {
return Object.prototype.toString.call(arg) == '[object Array]';
};
}
Cross-browser compatibility
Based on Kangax's compat table.
| Feature | Firefox (Gecko) | Chrome | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | 4 (2.0) | 5 | 9 | -- | 5 |
| Feature | Firefox Mobile (Gecko) | Android | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|
| Basic support | ? | ? | ? | ? | ? |
See also
- Bug 510537 - ES5: Array.isArray