Dynamically create object keys in IE 11 (Expected identifier, string or number, not a comma issue)

后端 未结 1 1732
广开言路
广开言路 2021-01-18 06:35

I\'m looking for a solution that creates object keys (is that worded correctly?) dynamically.

Arbitrary example, but this works in chrome and firefox



        
1条回答
  •  无人及你
    2021-01-18 07:03

    IE11 is not a "modern" web browser in the same way Chrome, Firefox or even Edge is. It doesn't support the new "object literal extensions" from ES6 (ES2015).

    The syntax you are using is called "computed property keys", you cannot use it in IE11. You need to do this the "old fashioned" way.

    var weeks = {};
    
    for(var i = 0; i < 5; i++){
        var tmp = {};
        tmp["week" + i] = i*2;
    
        $.extend(weeks, tmp);
    }
    

    0 讨论(0)
提交回复
热议问题