判断数组方式
1.Object.prototype.tostring.call()
//返回一个表示对象类型的字符串([object Array])
console.log(Object.prototype.toString.call(a));
2.原型链
function isArrayUsingPrototype(obj) {
// 参数一 函数上下文
// 参数二 要检查的对象
return Object.prototype.isPrototypeOf.call(Array.prototype, obj);
}
console.log(isArrayUsingPrototype(a));
3.es6中Array.isArray()判断
// 返回true和false
console.log(Array.isArray(a));
4.instanceof判断
console.log(a instanceof Array);
5.Array.prototype.isprototypeof()
// 返回true和false
console.log(Array.prototype.isPrototypeOf(a));
阅读剩余
版权声明:
作者:Shican_FelixLiu
链接:https://www.shicanyyds.cn/index.php/2025/04/12/%e5%88%a4%e6%96%ad%e6%95%b0%e7%bb%84%e6%96%b9%e5%bc%8f/
文章版权归作者所有,未经允许请勿转载。
THE END









