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
网友评论