判断JS对象是不是数组
2014-11-25 16:11
309 查看
function isArray(o) { return Object.prototype.toString.call(o) === '[object Array]'; }
原文如下 :
引用
The Miller Device
The JavaScript language currently does not provide a good way to distinguish between objects and arrays. The typeof operator is broken: It identifies arrays as objects. Comparing a value's constructor property doesn't work because arrays created in a different
frame will have a different constructor. There are do-it-yourself tests for arrayness, but they are complicated and unreliable.
Mark Miller of The Google, by closely reading the ECMAScript standard, has discovered a simpler, more reliable test.
Object.prototype.toString.apply(value) === '[object Array]'
相关文章推荐
- 判断一个js对象是不是数组
- JS中判断对象是不是数组的方法
- js判断对象是不是数组
- js 如何判断一个对象是不是数组
- 判断数据类型,判断是否空对象,js判断是不是数组
- JS判断对象是不是数组“Array”
- JS中判断对象是不是数组的方法
- JS判断对象是不是数组“Array”
- JS判断对象是不是数组“Array”
- Javascript 判断对象是不是数组
- js实现数组去重、判断数组以及对象中的内容是否相同
- js如何判断一个对象是不是Array?
- js如何判断一个对象是不是Array?
- js如何判断一个对象是不是Array?
- js如何判断一个对象是不是Array?
- 判断一个对象是不是数组
- 判断一个对象是不是JavaScript数组(怎样判断一个变量是数组)
- js实现数组去重,判断数组、对象中的内容是否相同
- js判断数组,对象是否存在某一未知元素
- javascript如何判断一个对象是不是数组