isArray() Function is used to check if a variable is an Array or not.
Let us say we have the below array with four elements.
var x = [5, 8, 2, 9]
-Function1.png)
And we want to check if the variable x holds an Array or not?
And isArray() function helps us achieve the above.
Let us see in the below example.
<html>
<body>
<script>
var x = [5, 8, 2, 9]
var y = Array.isArray(x)
if (y == true) {
document.write("Is an Array")
}
else if (y == false) {
document.write("No!! Is not an Array")
}
</script>
</body>
</html>