Array.isArray([]);
// true
// 尝试用一个类似数组的对象去测试
Array.isArray({
length: 1
,
"0": 1
,
slice: function() {}
}); // false
//如果你的开发环境不支持ECMAScript5,可以通过Object.prototype.toString()方法来代替。
if (
typeof Array.isArray === "undefined"
) {
Array.isArray =
function(arg) {
return Object.prototype.toString.call(arg) === "[object Array]"
;
};
}
转载于:https://www.cnblogs.com/qzsonline/archive/2013/04/24/3039595.html