Check if an object is an array:
const fruits = ["Banana", "Orange", "Apple", "Mango"];
let result = Array.isArray(fruits);
Try it Yourself »
Check if another datatype is an array:
let text = "91xjr";
let result = Array.isArray(text);
Try it Yourself »
The isArray()
method returns true
if an object is an array, otherwise false
.
Array.isArray() is a static property of the JavaScript Array object.
You can only use it as Array.isArray().
Using x.isArray(), where x is an array will return undefined.
Array.isArray
(obj)
Parameter | Description |
obj | Required. An object (or any data type) to be tested. |
Type | Description |
A boolean | true if the object is an array, otherwise false . |
isArray()
is an ECMAScript5 (ES5) feature.
ES5 (JavaScript 2009) fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 9-11 |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!