js判断变量是不是数组
var arr= [1,2,3,4]; function isArray(o) { return Object.prototype.toString.call(o)== '[object Array]'; } console.log(isArray(arr));
//Object.prototype.toString.call([]) '[object Array]'
//Object.prototype.toString.call({}) '[object Object]'
//Object.prototype.toString.call(1) '[object Number]'
//Object.prototype.toString.call('1') '[object String]'
//Object.prototype.toString.call(null) '[object Object]'
//Object.prototype.toString.call(undefined) '[object Undefined]'