Reputation: 1586
I have the following code that works perfectly fine in Chrome etc, but doesn't work in IE 11:
var fieldName="UserField";
var fieldValue="update value here..."
var obj = {
id: 123,
[fieldName]: fieldValue
};
var message="The field ["+ fieldName +"] will be updated with the value of ["+ obj[fieldName] +"]";
Here is a plunker that shows the problem
Since the variable is dynamic, I can't just hard-code it in.
Any idea how I can get it to work in IE?
Upvotes: 1
Views: 1466
Reputation: 42526
Computed property names in objects are not supported in Internet Explorer (but they are supported by the newer Edge browsers).
You might need to take that into account if you are working with lots of IE users.
Upvotes: 0
Reputation: 386604
IE does not support computed property names.
You could take a classic property accessor.
var fieldName = "UserField",
fieldValue = "update value here...",
obj = { id: 123 };
obj[fieldName] = fieldValue;
var message = "The field [" + fieldName + "] will be updated with the value of [" + obj[fieldName] + "]";
console.log(message);
Upvotes: 3