判断数组类型的方法

判断是数组的方法

var arr = [1,2,3]

第一种: Array.isArray(arr)

第二种:arr instanceof Array      (instanceof 是判断原型上是否继承数组的原型)

第三种:Object.prototype.toString.call(arr).indexOf("Array")>-1

第四种:Array.prototype.isPrototypeOf(arr)

第五种:arr.constructor.toString()

posted @ 2022-03-08 18:11  踏浪小鲨鱼  阅读(77)  评论(0)    收藏  举报