function type(o) {
const type = Object.prototype.toString.call(o)
return type.match(/\[object (.*)\]/)[1].toLowerCase()
}
console.log(type({}));//object
console.log(type([]));//array
console.log(type());//undefined
console.log(type(null));//null
js判断数据类型
![](https://img-home.csdnimg.cn/images/20240711042549.png)