jQuery isArray() examples

jQuery isArray() function is used to determine whether the argument is an array.

Syntax

jQuery.isArray( obj )
obj - Object to test whether or not it is an array.

Example

<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>jQuery.isArray demo</title>
    <script src="https://code.jquery.com/jquery-3.4.1.js"></script>
</head>

<body>

    Is [] an Array? <b id="b1"></b> <br> fruits an Array? <b id="b2"></b><br> obj an Array <b id="b3"></b>

    <script>
        $("#b1").append("" + $.isArray([]));

        var fruits = ["Banana", "Orange", "Apple", "Mango"];
        $("#b2").append("" + $.isArray(fruits));

        var obj = {};
        $("#b3").append("" + $.isArray(obj));
    </script>

</body>

</html>
Output:
Is [] an Array? true 
fruits an Array? true
obj an Array false

References



Comments