Array.isArray() 方法用于确定某个值是否是数组类型。
Array.isArray( value )
| 参数 | 说明 | 类型 |
|---|---|---|
value | 需要检测的值 | any |
返回值: 如果对象是 Array 的实例,则返回 true ;否则为 false。
下面的函数调用都返回 true
Array.isArray([])Array.isArray([1])Array.isArray(new Array())Array.isArray(Array.prototype)
鲜为人知的事实:其实 Array.prototype 也是一个数组。
Array.isArray(Array.prototype)
下面的函数调用都返回 false。
Array.isArray()Array.isArray({})Array.isArray(null)Array.isArray(undefined)Array.isArray(17)Array.isArray('Array')Array.isArray(true)Array.isArray(false)Array.isArray({ __proto__: Array.prototype })