Skip to content

WebDevHubs

  • Home
  • HTML
  • CSS
  • JavaScript
  • Web Technologies
  • Web Templates
  • Toggle search form

JavaScript Array isArray() Method

Posted on June 16, 2025June 16, 2025 By Admin No Comments on JavaScript Array isArray() Method

JavaScript Array isArray() method is used to determine whether a given value is an array. It returns a boolean value: true if the value is an array, and false otherwise. This method is particularly useful when working with dynamic data structures or verifying input types in your code.

Pre-requisites to Learn

  • JavaScript Array

Syntax

Array.isArray(value);

Parameters

ParameterDescription
valueThe value to be checked if it is an array or not.

Return Value

The Array.isArray() method returns true if the provided value is an array, otherwise returns false.

Examples of JavaScript Array isArray() Method

Example 1: Checking Simple Arrays

console.log(Array.isArray([1, 2, 3])); // Output: true
console.log(Array.isArray('Hello'));   // Output: false
console.log(Array.isArray(123));       // Output: false

Here, the method accurately identifies the array [1, 2, 3] and rejects non-array types like strings and numbers.

Example 2: Differentiating Between Arrays and Objects

let obj = { name: 'John', age: 30 };
let arr = [10, 20, 30];

console.log(Array.isArray(obj)); // Output: false
console.log(Array.isArray(arr)); // Output: true

This example demonstrates that Array.isArray() correctly distinguishes between objects and arrays.

Example 3: Checking Nested Arrays

let nestedArray = [[1, 2], [3, 4]];
let notArray = { 0: 'a', 1: 'b', length: 2 };

console.log(Array.isArray(nestedArray)); // Output: true
console.log(Array.isArray(notArray));    // Output: false

Even for nested arrays, the method returns true, while it rejects array-like objects.

Supported Browsers

BrowserSupport
Chrome5+
Firefox4+
Safari5+
Edge12+
Opera10.5+
Internet Explorer9+
JavaScript, Web Technologies Tags:JavaScript-Array, JavaScript-Array-Method, JavaScript-Method

Post navigation

Previous Post: JavaScript Array forEach() Method

Leave a Reply Cancel reply

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

Archives

  • June 2025
  • May 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024

Categories

  • CSS
  • HTML
  • JavaScript
  • Lodash
  • PHP
  • Python
  • Web Technologies
  • Web Templates

Recent Posts

  • JavaScript Array isArray() Method
  • JavaScript Array forEach() Method
  • JavaScript Array includes() Method
  • JavaScript Array keys() Method
  • JavaScript Array lastIndexOf() Method

Recent Comments

No comments to show.

Copyright © 2025 WebDevHubs.

Powered by PressBook Green WordPress theme