This AI is still in early stages of development.
object.isArray
- Aubergine
Owned by Aubergine
A quick way to check if an object is an array...
Syntax
The .isArray
property is added to all objects, but only returns true
on arrays.
var returnValue = obj.isArray;
Return value
Value | Type | Notes | API Version |
---|---|---|---|
true | Boolean | The object is an array | 1.0 |
false | Boolean | The object is not an array | 1.0 |
Examples
Pre-check that a value is not null
before using .isArray
...
var val = null; if (val.isArray) { // Reference Error (null.isArray not defined) } if (val && val.isArray) { // false // do stuff if array } // alternate approach using typeOf() if (typeOf(val) == "array") { // false // do stuff if array }
The arguments object inside functions is not a real array...
The arguments object isn't an array!
function foo() { if (arguments.isArray) { // false // will never get called } // turn in to a real array with toArray() arguments = toArray(arguments); if (arguments.isArray) { // true // will get called } }
Contents
Jump to:
Type Checking
Topics:
- classOf() — Returns the name of the class (constructor) used to create an object...
- object.isFunction — A quick way to check if an object is a function...
- typeOf() — Returns a more accurate object type name than Javascript's native "typeof https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/typeof" operator...
- object.isArray — A quick way to check if an object is an array...