JavaScript检测数据类型
标签(空格分隔): JavaScript
function valType(value) {
return Object.prototype.toString.call(value).slice(8, -1);
}
valType('a');
// "String"
valType(123);
// "Number"
valType({ a: 1 });
// "Object"
valType(['1', 2]);
// "Array"
valType(true);
// "Boolean"
valType(null);
// "Null"
valType(undefined);
// "Undefined"
valType(new Date());
// "Date"
valType(Math);
// "Math"
原文地址:https://www.cnblogs.com/jehorn/p/10579094.html
时间: 2024-10-28 20:10:46