The best way:
function isArray(obj) {
return Object.prototype.toString.call(obj) == '[object Array]';
}
Run Code Online (Sandbox Code Playgroud)
The ECMAScript 5th Edition Specification defines a method for that, and some browsers, like Firefox 3.7alpha, Chrome 5 Beta, and latest WebKit Nightly builds already provide a native implementation, so you might want to implement it if not available:
if (typeof Array.isArray != 'function') {
Array.isArray = function (obj) {
return Object.prototype.toString.call(obj) == '[object Array]';
};
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1145 次 |
| 最近记录: |