javaScript Check Object is Array| isArray() Function

javaScript Check Object is Array| isArray() Function

In this tutorial, you will learn all about javascript array.isArray() method. And how to use this method.

JavaScript isArray()

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

Note that, this is the built-in javascript array method.

isArray() Syntax

Array.isArray(obj)

This method returns the boolean value. If the passed argument is array this method returned true, otherwise return 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

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 *