getDataType.js 内容如下:
/**
* 获取数据的类型
* @param {any} obj
*/
const getDataType = function (obj) {
return Object.prototype.toString.call(obj).replace(/^\[object\s(\w+)\]$/, '$1').toLowerCase();
};
export default getDataType
使用方法:
getDataType({})
> 'object'
getDataType([])
> 'array'
getDataType()
> 'undefined'
getDataType(null)
> 'null'
getDataType(new Date())
> 'date'
getDataType(async ()=>{})
> 'asyncfunction'
getDataType(()=>{})
> 'function'