前言
以下是我总结的四种判断方法,与大家一起分享:
1. 检查class:
Object.prototype.toString.call(arr) = "[object Array]"
2. Array的原型链
Array.prototype.isPrototypeOf(arr) = true
3. 判断构造函数
arr instanceof Array = true
4. Array自带API
Array.isArray(arr) = true
以下是我总结的四种判断方法,与大家一起分享:
Object.prototype.toString.call(arr) = "[object Array]"
Array.prototype.isPrototypeOf(arr) = true
arr instanceof Array = true
Array.isArray(arr) = true
本文标题:JS 如何判断是否为数组类型
本文链接:https://www.haomeiwen.com/subject/digtohtx.html
网友评论