列举区别object,array的几种简单方法,特此记录下
var arr = []
var obj = {}
// 1. 通过Array的isArray方法判读
console.log(Array.isArray(arr)) //true
console.log(Array.isArray(obj)) // false
// 2.通过instancesOf 运算符
console.log(arr instanceof Array) // true
console.log(obj instanceof Array) // false
// 3.通过数组prototype的isPrototypeOf方法
console.log(Array.prototype.isPrototypeOf(arr)) // true
console.log(Array.prototype.isPrototypeOf(obj)) // false
// 4.通过构造函数constructor
console.log(arr.constructor == Array) // true
console.log(obj.constructor == Array) // false