实现兼容的isArray()方法

function isArray(val) {
    return Object.prototype.toString.call(val) === "[object Array]";
}
var arr1 = [1,2,3],arr2 = '123';
console.log(isArray(arr1),isArray(arr2));//true false
console.log(Object.prototype.toString.call(arr1));//[object Array]
console.log(Object.prototype.toString.call(arr2));//[object String]

你可能感兴趣的:(js学习笔记,js,数组)