Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

array
jquery
isarray
communitycreator

How to check if a value is an array in jQuery

Programming Bytes

Overview

We can use the isArray method to check if an object is an array or not.

Syntax

jQuery.isArray( obj )

Arguments

obj: This is the object to be tested.

Return value

The isArray method returns true if the argument passed is an array. Otherwise, false is returned.

Code

The code below demonstrates how to check if an object is an array using jQuery.

Console
Use the isArray method to check if an object is an array

Code explanation

Here is a line-by-line explanation of the above code.

  • Line 5: We include the jQuery file.

  • Lines 7 and 8: We create an array arr and call the isArray method with the created array. The isArray method will return true.

  • Lines 10 and 11: We create an empty object obj and call the isArray method with the created object. The isArray method will return false because the argument passed to the isArray method is not an array.

RELATED TAGS

array
jquery
isarray
communitycreator
RELATED COURSES

View all Courses

Keep Exploring