万能检测数据类型的办法「返回结果:”小写数据类型”」
const toString = Object.prototype.toStringconst toType = function toType(obj) {if (obj === null) return "null"let type = typeof obj,reg = /^\[object (\w+)\]$/if (/^(object|function)$/.test(type)) {// 检测的值是对象type = toString.call(obj)return reg.exec(type)[1].toLowerCase()}// 检测的值是原始值return type}
