Use bracket notation instead.
var name = otherObject.name;
var o = {};
o[name] = otherObject;
Or, in modern JavaScript:
var o = {
[name]: otherObject,
};
More Related Contents:
- JSON to string variable dump
- How to insert into JSON?
- How to use a variable for a key in a JavaScript object literal?
- Convert array to JSON
- How to pass json POST data to Web API method as an object?
- Is the order of elements in a JSON list preserved?
- jQuery.parseJSON throws “Invalid JSON” error due to escaped single quote in JSON
- Sum JavaScript object propertyA values with the same object propertyB in an array of objects
- SyntaxError: Unexpected token o in JSON at position 1
- Angular 5 Service to read local .json file
- How to serialize DOM node to JSON even if there are circular references?
- How to convert JSON to CSV format and store in a variable
- Merge keys array and values array into an object in JavaScript
- How might I extract the property values of a JavaScript object into an array?
- JavaScript OR (||) variable assignment explanation
- Is there any difference between declared and defined variable
- Is this simple string considered valid JSON?
- How to inject HTML into a template with polymer
- Setting a variable equal to another variable [duplicate]
- How to use Select2 with JSON via Ajax request?
- How to write data to a JSON file using Javascript
- Javascript show element on click
- Not a Legal JSONP API — How to get data without CALLBACK parameter
- d3 js – loading json without a http get
- JSON syntax for property names
- IE10/11 Ajax XHR error – SCRIPT7002: XMLHttpRequest: Network Error 0x2ef3
- Should JSON include null values [closed]
- TypeError: Converting circular structure to JSON in nodejs
- Parsing JSON containing new line characters [duplicate]
- Push JSON Objects to array in localStorage