美文网首页
js判断数据类型

js判断数据类型

作者: 小光啊小光 | 来源:发表于2020-05-15 17:52 被阅读0次
    let arr = [a: 1, b: 2]
    let obj = {a: 1, b: 2}
    
    typeof arr  // object 
    arr instanceof Object // true
    arr instanceof Array  // true
    arr.constructor === Array // true
    Array.isArray(arr) // true *推荐
    Object.prototype.toString.call(arr) === '[object Array]' // true *推荐
    
    typeof obj // object
    obj instanceof Object // true
    obj.constructor === Object // true
    Object.prototype.toString.call(obj) === '[object Object]' // true *推荐
    

    相关文章

      网友评论

          本文标题:js判断数据类型

          本文链接:https://www.haomeiwen.com/subject/cshhohtx.html