本文共 620 字,大约阅读时间需要 2 分钟。
var arr = [1,2,3,4,5]
方法一
arr instanceof Array
方法二
Array.isArray(arr)
方法三
Object.prototype.toString.call(arr) === "[object Array]"
console.log(Object.prototype.toString.call(123)) //[object Number]
console.log(Object.prototype.toString.call('123')) //[object String] console.log(Object.prototype.toString.call(undefined)) //[object Undefined] console.log(Object.prototype.toString.call(true)) //[object Boolean] console.log(Object.prototype.toString.call({})) //[object Object] console.log(Object.prototype.toString.call([])) //[object Array] console.log(Object.prototype.toString.call(function(){})) //[object Function]
转载地址:http://ystrz.baihongyu.com/