Code stuff about Javascript on Aug 31, 2008

How to check if a Javascript variable is an array

Looking for the simplest way to check if a Javascript variable / object is an array? Here’s a simple way on how to check for an Array variable in javascript:

function isArray(variable) {
if (variable.constructor == Array)
return true;
else
return false;
}

or better yet, just do this:

function isArray(variable) {
return (variable.constructor == Array);
}

Related posts

Leave a Reply