判断数据类型三种办法

49 阅读1分钟

XXX.constructor==内置对象

    var str=["hello word"]
    console.log(str.constructor==Array) //true

typeOf xxx

    var str=["hello word"]
    console.log(typeOf str) //Object

Object.prototype.toString.call(xxx)

    var str=["hello word"]
    console.log(Object.prototype.toString.call(str)) //[Object Array]

xxx instanceof 内置对象

    var str=["hello word"]
    console.log(str instanceof Array) //true