Below is the example of the Array isArray() method.
- Example:
<script>// JavaScript code for isArray() functionfunctionfunc() {document.write(Array.isArray('foobar'));}func();</script>chevron_rightfilter_none - Output:
false
The arr.isArray() method determines whether the value passed to this function is an array or not. This function returns true if the argument passed is array else it returns false.
Syntax:
Array.isArray(obj)
Parameters: This method accept a single parameter as mentioned above and described below:
- obj: This parameter holds the object that will be tested.
Return value: This function returns the Boolean value true if the argument passed is array otherwise it returns false.
Below example illustrate the Array isArray() method in JavaScript:
- Example 1: Since the argument passed to the function isArray() is an array therefore this function returns true as the answer.
Input : print(Array.isArray(['Day','Night','Evening'])); Output: true
- Example 2: Since the argument passed to the function isArray() is a map therefore this function returns false as the answer.
Input : print(Array.isArray({foo: 123})); Output: false - Example 3: Since the argument passed to the function isArray() is a string therefore this function returns false as the answer.
Input : print(Array.isArray('foobar')); Output: false
Code for the above method is provided below:
Program 1:
<script> // JavaScript code for isArray() function function func() { document.write(Array.isArray(['Day','Night','Evening'])); } func(); </script> |
Output:
true
Program 2:
<script> // JavaScript code for isArray() function function func() { document.write(Array.isArray({foo: 123})); } func(); </script> |
Output:
false
Supported Browsers: The browsers supported by JavaScript Array isArray() method are listed below:
- Google Chrome 5.0
- Microsoft Edge 9.0
- Mozilla Firefox 4.0
- Safari 5.0
- Opera 10.5
Recommended Posts:
- JQuery | isArray() method
- Lodash _.isArray() Method
- Underscore.js | _.isArray()
- AngularJS | angular.isArray() Function
- PHP | ReflectionParameter isArray() Function
- How to compare two JavaScript array objects using jQuery/JavaScript ?
- How to move an array element from one array position to another in JavaScript?
- How to get the elements of one array which are not present in another array using JavaScript?
- What’s the difference between “Array()” and “[]” while declaring a JavaScript array?
- How to check whether an array is subset of another array using JavaScript ?
- How to convert Integer array to String array using JavaScript ?
- Difference between array.size() and array.length in JavaScript
- What is the difference between Array.slice() and Array.splice() in JavaScript ?
- How to convert Object's array to an array using JavaScript ?
- JavaScript Course | Understanding Code Structure in JavaScript
- Introduction to JavaScript Course | Learn how to Build a task tracker using JavaScript
- JavaScript Course | Loops in JavaScript
- JavaScript Course | Data Types in JavaScript
- JavaScript Course | Printing Hello World in JavaScript
- JavaScript Course | Logical Operators in JavaScript
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


