1、instanceof
function isArray(obj) {
return obj instanceof Array;
}
function isObject(obj){
return obj instanceof Object;
}
var arr=[1,2,3,4,5,6];
var object={name:'jim'};
console.log(isArray(arr),isObject(object));
2、Object.prototype.toString.call(obj)=='[object Array]'
function isArray(obj) {
return Object.prototype.toString.call(obj)=='[object Array]';
}
function isObject(obj){
return Object.prototype.toString.call(obj)=='[object Object]';
}
var arr=[1,2,3,4,5,6];
var object={name:'jim'};
console.log(isArray(arr),isObject(object));