1
function replaceJsonStringify( key, value1 ) {

    var $edit = $("#trafficLog");
    var currentValue = $edit.val();
    var jsonConnect = { "time":getLongTime(), [key] : value };
    var jsonObj = JSON.stringify(jsonConnect);
    var newValue = jsonObj + "<br>" + currentValue;

    $edit.val(replaceBR(newValue));   }

replaceJsonStringify( "connectFlag", connect );

I want to rename the json key's value.

The above code works fine in Chrome, but it is not working in IE11, 10..

I want to know how to rename the json key's value.

The problem in the code is " [key] : value "

IE debugging : SCRIPT1028: Expected identifier, string or number.

Please answer about this problem.

Zenoo
  • 12,670
  • 4
  • 45
  • 69
sinred123
  • 9
  • 4
  • Share a working snippet using `<>` from the toolbar that demonstrate your problem. – gurvinder372 Mar 08 '18 at 11:03
  • Possible duplicate of [Dynamically create object keys in IE 11 (Expected identifier, string or number, not a comma issue)](https://stackoverflow.com/questions/37392656/dynamically-create-object-keys-in-ie-11-expected-identifier-string-or-number) – Suresh Ponnukalai Mar 08 '18 at 11:08

2 Answers2

0

I guess IE can't understand yet computed properties in the object. Change this:

var jsonConnect = { "time":getLongTime(), [key] : value };

to this:

var jsonConnect = { time: getLongTime() }
jsonConnect[key] = value;
dfsq
  • 191,768
  • 25
  • 236
  • 258
0

IE doesn't have support for computed property names. You need to replace this line:

var jsonConnect = { "time":getLongTime(), [key] : value };

with this:

var jsonConnect = { "time":getLongTime() };
jsonConnect[key] = value;

See this document for more details.

31piy
  • 23,323
  • 6
  • 47
  • 67