IE问题 - 不支持Object.keys(value).length [英] IE issue - Object.keys(value).length not supported

查看:370
本文介绍了IE问题 - 不支持Object.keys(value).length的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试在Internet Explorer中调试一些js,我无法弄清楚这一点。以下是导致错误的行:

I've been trying to debug some js in Internet Explorer, and I can't figure this one out. Here's the line that is causing the error:

var numberOfColumns = Object.keys(value).length;

错误是......

Message: Object doesn't support this property or method
Line: 640
Char: 5
Code: 0
URI: xxx

起初我认为它与 Object.keys(值有关) ).length; 属性,但奇怪的是(反正对我来说),错误在char 5,这是变量名的开头。

At first I thought it had something to do with the Object.keys(value).length; property, but strangely (for me anyways), the error is at char 5, which is the beginning of the variable name.

无论如何,我不知道发生了什么或如何解决它。另外,如果我替换:

Anyways, I have no idea what's going on or how to fix it. Also, if I replace:

var numberOfColumns = Object.keys(value).length;

随... ...

var numberOfColumns = 9; // troubleshooting

错误仍然存​​在。请帮忙。

The error persists. Please help.

更新

jsFiddle添加

jsFiddle added

http://jsfiddle.net/4Rab7/

推荐答案

IE> = 9支持属性。您可能正在测试它早期版本。一个简单的解决方法是:

The keys property is supported in IE >= 9. You are probably testing it in an earlier version. A simple workaround is:

var length = 0;
for(var prop in data){
    if(data.hasOwnProperty(prop))
        length++;
}

这是一个演示: http://jsfiddle.net/vKr8a/

有关详细信息,请参阅此兼容性表:

See this compatibility table for more info:

http://kangax.github.com/es5-compat-table/

这篇关于IE问题 - 不支持Object.keys(value).length的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆