Check if variable is array in JavaScript


Check if variable is array in JavaScript – There are many ways to check a variable is array or not using javascript. Here in this tutorial we are going to explain this using few methods with example and demo.


How to Check if variable is array in JavaScript

You can use the below method to check the variable whether it is array or not. It is simple and fast.

Check if variable is array in JavaScript Example:

<script type="text/javascript">
function checkArray() {
var a = []; // array declaration
if(a.constructor === Array){
alert("Array");
}else{
alert("Not An Array");
}
}

</script>

Try it »


Advertisements

Add Comment

📖 Read More