Open artdong opened 4 years ago
let _toString = Object.prototype.toString; function getType (value) {return _toString.call(value).slice(8, -1)}
getType(); // "Undefined" getType(''); // "String" getType(1); // "Number" getType(1n); // "BigInt" getType(Symbol('uid')); // "Symbol" getType(true); //"Boolean" getType([]); //"Array" getType({}); //"Object" getType(null); //"Null" getType(function(){}); //"Function"
判断js数据类型最简方法