如何判断一个js对象是数组类型,判断数据类型

判断一个对象是哪个类型:constructor

var test=new Array();
    if(test.constructor==Array){
        document.write("this is an Array")
    }else if(test.constructor==Boolean){
        document.write("this is a Boolean")
    }else if(test.constructor==String){
        document.write("this is a String")
    }else if(test.constructor==Date){
        document.write("this is a Date")
    }


判断数据类型:typeof

typeof a


你可能感兴趣的:(javascript)