Check if an argument is an Array in javascript








var isArray(obj){
if(obj.constructor.toString().indexOf(‘Array’)!=-1) {
return true;
} else {
return false;
};
}

Tips:
You can alert(obj.constructor);
to see the string value.
Similarly, you can check if an argument is an function with following
code:
var isFunction(obj){
if(obj.constructor.toString().indexOf('Function')!=-1){
return true;
} else {
return false;
}
};




No comments:

Post a Comment