如题所述
function objectType(param) {
var oType = typeof param;
if (oType === 'object') {
if (param === null)
return 'null';
if (Array.isArray(param))
return 'array'
}
return oType;
}
//æµè¯
objectType({}); // 'object'
objectType([]); // 'array'
objectType(null): // 'null'
objectType(): // 'undefined'
objectType(123): // 'number'
objectType('123'): // 'string'
var oType = typeof param;
if (oType === 'object') {
if (param === null)
return 'null';
if (Array.isArray(param))
return 'array'
}
return oType;
}
//æµè¯
objectType({}); // 'object'
objectType([]); // 'array'
objectType(null): // 'null'
objectType(): // 'undefined'
objectType(123): // 'number'
objectType('123'): // 'string'
温馨提示:答案为网友推荐,仅供参考
第1个回答 2017-10-17
用typeof