https://my.oschina.net/ohcoding/blog/470952?p=1
var a = ['hello','world']; console.log(typeof a); // object console.log(a.toString()); // hello,word 字符串 console.log(Object.prototype.toString.call(a)); //[object Array] var b = {'hello':'world'}; console.log(typeof b); // object console.log(b.toString()); // [object Object] console.log(Object.prototype.toString.call(b));// [object Object]
1. Array 和 Object 的typeof 结果都是 object
2. toString() Array的结果是真的字符串,而Object的结果是固定的[object Object]
3. 通过Object.prototype.toString调用,Array的结果返回固定[object Array],Object的结果依然是[object Object]
ES2005 新方法
console.log( Array.isArray(a) ); // true console.log( Array.isArray(b) ); // false