JAVASCRIPT:在IE中创建动态密钥 [英] JAVASCRIPT : create dynamic key in IE
本文介绍了JAVASCRIPT:在IE中创建动态密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var jsonUiid = "sdfsdf";
a={
[jsonUiid] : {
"heading":"title"
}
};
直接在开发人员工具中尝试过. 上面的代码在所有浏览器中都适用. 在Internet Explorer中失败.请帮忙.
Tried directly in developer tools. The above code works in all browsers. It fails in Internet Explorer. Please help.
如果我们不使用方括号[],它将直接获取"jsonUiid",而不是上面定义的实际值.
If we don't square bracket[], it directly gets "jsonUiid" rather than the actual value defined above.
推荐答案
计算的属性名称是ES6的一部分,目前并非所有浏览器都完全支持.您可以使用旧式方括号表示法:
Computed property names are part of ES6 which is currently not fully supported by all browsers. You can set object property with old-style bracket notation:
var jsonUiid = "sdfsdf";
var a = {};
a[jsonUiid] = {
"heading": "title"
};
这篇关于JAVASCRIPT:在IE中创建动态密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文