javaScript Check Object is Array| isArray() Function

javaScript Check Object is Array| isArray() Function

isArray() – Today we would love to share with you javascript isArray method. How it work this methods. We will give some examples of isArray().

JavaScript isArray()

The JavaScript isArray() function determines whether the value given to this function is an array or not. If this argument is correct then this function is return true, otherwise it is false.

isArray() Syntax

Array.isArray(obj)

This function returns the boolean value. If the passed argument is array this function returned true, otherwise it is false.

Example 1

var arr = [5, 3, 10, 1, 6, 12]

document.write("Check if passed value array or not"); 
document.write("<br><br>"); 
document.write("Retrun value = " + Array.isArray(arr)); 
Output /////
Check if passed value array or not
Retrun value = true

We have passed an array in the IsArray () function. Therefore Returning the true.

Example 2

var arr = 'foobar';

document.write("Check if passed value array or not"); 
document.write("<br><br>"); 
document.write("Retrun value = " + Array.isArray(arr)); 
Output ///

Check if passed value array or not
Retrun value = false

We have passed the string value in the isArray () function. Therefore this function is returning the false .

Example 3

var arr = [
    ['php', 'python', 'perl'],
    ['xampp', 'mysql', 'sql'],
    ['jquery', 'javaScript', 'angular', 'react']
];

document.write("Check if passed value array or not"); 
document.write("<br><br>"); 
document.write("Retrun value = " + Array.isArray(arr)); 
Output///

Check if passed value array or not

Retrun value = true

Since the argument passed to the function isArray() is an array therefore this function returning true.

You may like

  1. JavaScript Array splice() Method By Example
  2. Sorting Using JavaScript Array Sort() Method
  3. JavaScript: Clone an Array & Object By Examples
  4. JavaScript: Convert String to Array JavaScript
  5. Remove (First, last, specific) Element From Array Javascript
  6. javaScript Push() Array By Example
  7. javaScript Push Array, Items Into Array Example
  8. JavaScript: Important Array Methods


Leave a Reply

Your email address will not be published. Required fields are marked *