typeof判断数据类型不精准? 试试这个

阅读 173

2022-02-08

typeof([1,2,3])
'object'  //我想要的是Array 不够精准
Object.prototype.toString.call([1,2,3])
'[object Array]'
Object.prototype.toString.call(1)
'[object Number]'
Object.prototype.toString.call(null)
'[object Null]'
Object.prototype.toString.call(undefined)
'[object Undefined]'
Object.prototype.toString.call('1')
'[object String]'

精彩评论(0)

0 0 举报