jQuery.isArray()    **DEPRECATED 3.2** JQ Home  <<  Utilities  <<  jQuery.isArray()

Array object detection.

Description

The jQuery.isArray() jQuery Type utility method, returns a boolean dependant upon the specified object being a JavaScript Array object.

Shorthand version $.isArray()

  • Only returns true for Array objects, not array-like objects. Objects that are array-like in nature have characteristics similar to an array.
    1. Generally with array-like objects you can use the array access operator[] and the length property for example.
    2. You do not get full access to the methods of a true Array object.

This method was deprecated in jQuery 3.2.

Syntax

Signature Description
jQuery.isArray( object )Return a boolean dependant upon the specified object being a JavaScript Array object.

Parameters

Parameter Description Type
objectThe object to test to see if it is an Array object.Object

Return

A Boolean object.

jQuery.isArray( object ) Example Utilities  <<  Top

Return a boolean dependant upon the specified object being a JavaScript Array object.

In the example below when we press the button we create some variables and test to see if they are Array objects.



$(function(){
  $('#btn1').one('click', function(){
    var obj1 = 'A string', obj2 = [], obj3 = {}, obj4 = new Object;
    $('#div1').append('Is obj1 an Array object? ' +  $.isArray( obj1 ) + '<br>');
    $('#div1').append('Is obj2 an Array object? ' +  $.isArray( obj2 ) + '<br>');
    $('#div1').append('Is obj3 an Array object? ' +  $.isArray( obj3 ) + '<br>');
    $('#div1').append('Is obj4 an Array object? ' +  $.isArray( obj4 ) + '<br>');
  });
});

div1. Some initial text.

Press the button below to action the above code:

Related Tutorials

jQuery Intermediate Tutorials - Lesson 10 - jQuery Copy, Data & Type Utilities