Object.prototype.toString检测对象类型

let arr = [];
let obj = {};
function fun(){
	
}
let toString = Object.prototype.toString;
// 检测数组类型
console.log(toString.call(arr) === '[object Array]'); // true
// 检测对象类型
console.log(toString.call(obj) === '[object Object]'); // true
// 检测函数类型
console.log(toString.call(fun) === '[object Function]'); // true

你可能感兴趣的:(前端)