天天看點

JS中判斷是否是對象

function isObject(o){

return !(o instanceof Array) && o instanceof Object

}

console.log(isObject([]));

console.log(isObject({}));

console.log(isObject('sss'));

console.log(isObject(undefined));

console.log(isObject(123));

console.log(isObject(null));

console.log(isObject(true));

繼續閱讀