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

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including 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. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

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