js中判断数据类型的方法

152 阅读1分钟

function getType(obj) { let type = typeof obj if (type != 'object') { return type } return Object.prototype.toString.call(obj).replace(/^[object (\S+)]/,/, '1') }

function typeOf(obj) { return Object.prototype.toString.call(obj).slice(8, -1).toLowerCase() }