jQuery inArray() and isArray() methods

In jQuery inArray and isArray are important functions. inArray checks if an element or value present in a given array. And isArray function check if given variable or value is array or not. Both functions are described below in detail: inArray function inArray checks if an element or value present in a given array. it takes two argument first is value and second is array which we need to look the given value. If the value found in the given array it return index of the value otherwise it returns -1. Example is mentioned below:


<html>
<head>
    <title>Example</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>

<script>
var number_var = [101, 201, 301, 401];
alert($.inArray(301, number_var)); // will return 2
alert($.inArray(501, number_var)); // will return : -1
</script>

</body>
</html>
isArray function isArray function check if given variable or value is array or not. It takes one argument and return true if the given variable is array otherwise it returns false. Example is mentioned below:

<html>
<head>
    <title>Example</title>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>

<script>
var number_var= [1, 2, 3];

alert($.isArray(number_var)); // will return : true

</body>
</html>