判断数据类型

141 阅读1分钟
1.Object.prototype.toString

Object.prototype.toString.call('') 

"[object String]"

 Object.prototype.toString.call([]) 

"[object Array]" 

Object.prototype.toString.call({})

 "[object Object]" 

Object.prototype.toString.call(1) 

"[object Number]" 

Object.prototype.toString.call(null) 

"[object Null]" 

Object.prototype.toString.call(undefined) 

"[object Undefined]"