javaScript Check Object is Array| isArray() Function

javaScript Check Object is Array| isArray() Function

To check object is an array in javascript; In this tutorial, you will learn how to check object is array in javascript and array object is empty or not.

Sometimes, you need to check array objects; So this tutorial will show you multiple examples of how to check array objects in the array. And it has been empty or not in javascript

How to Check Object is Array In JavaScript

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

Recommended JavaScript Tutorials


AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published.