function judgeArr(arr){ console.log(typeof arr); console.log(Array.isArray(arr)); console.log(Object.prototype.toString.call(arr)); console.log(); } judgeArr([]); judgeArr({}); judgeArr(''); judgeArr(1);
function judgeArr(arr){ return Array.isArray(arr); //或者 Object.prototype.toString.call(arr) == '[object Array]' }
function isArray(arg) { return Object.prototype.toString.call(arg).slice(8, -1) === 'Array' ? true : false; }