(info) This AI is still in early stages of development.

object.isArray

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

ValueTypeNotesAPI Version
trueBooleanThe object is an array1.0
falseBooleanThe object is not an array1.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
	}
}
Availability STABLE

Requires:

Contents

Jump to:

Type Checking

Topics:

  • classOf()Returns the name of the class (constructor) used to create an object...
  • object.isFunctionA 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.isArrayA quick way to check if an object is an array...