1、方法
<!--
* @Descripttion: 类型判断
* @version: 0.0.1
* @Author: PengShuai
* @Date: 2022年04月29日11:21:14
* @LastEditors: PengShuai
* @LastEditTime: 2022年04月29日11:21:14
-->
const typeOf = data => {
let type = Object.prototype.toString.call(data);
if (type === "[object String]") {
type = "String";
} else if (type === "[object Number]") {
type = "Number";
} else if (type === "[object Null]") {
type = "Null";
} else if (type === "[object Boolean]") {
type = "Boolean";
} else if (type === "[object Array]") {
type = "Array";
} else if (type === "[object Object]") {
type = "Object";
} else {
type = "未进行判断的类型:" + type;
}
return type;
};
2、例
![](https://img2020.cnblogs.com/blog/1563418/202201/1563418-20220110105752172-1244822991.png)