>Ob-6ren">
gpt4 book ai didi

javascript - IE8 - IsArray() 获取预期的错误对象

转载 作者:行者123 更新时间:2023-11-30 07:23:18 25 4
gpt4 key购买 nike

我很好奇为什么IE8会卡死

if (isArray(obj))

这是我在 IE8 javascript 控制台中得到的:

>>obj
{...}
>>typeof(obj)
"object"
>>Object.prototype.toString.call(obj)
"[object Array]"

甚至

>>obj.length
7

但是,

>>isArray(obj)
Object expected

为什么会这样(ie8 不支持 isArray?),最好的解决方法是什么?

我正在尝试为 IE8 使用新版本的 Angular。我知道它不受官方支持,但我会尝试使用该应用程序来更好或更差地工作。

谢谢。

最佳答案

从 IE 9 开始有 Array.isArray()。

试试这个:

Array.isArray = function (obj) {
return Object.prototype.toString.call(obj) === "[object Array]";
};

Array.isArray(obj);

关于javascript - IE8 - IsArray() 获取预期的错误对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29565477/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com