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 .
|
<!DOCTYPE html>
<html>
<head>
<title>JavaScript</title>
<script>
var a = ["Sanjay", "Aman", "Rehman"];
document.write(a + "<br><br>");
var b = Array.isArray(a);
document.write(b);
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>JavaScript</title>
<script>
var a = ["Sanjay", "Aman", "Rehman"];
if(Array.isArray(a)){
document.write("This is an Array");
}else{
document.write("This is not an Array");
}
</script>
</head>
<body>
</body>
</html>