You can use this equivalent syntax:
obj[name] = value
Example:
let obj = {};
obj["the_key"] = "the_value";
or with ES6 features:
let key = "the_key";
let obj = {
[key]: "the_value",
};
in both examples, console.log(obj)
will return: { the_key: 'the_value' }
More Related Contents:
- What does [object Object] mean?
- How does this JavaScript/jQuery syntax work: (function( window, undefined ) { })(window)?
- Converting a JS object to an array using jQuery
- Remove array element based on object property
- JavaScript: filter() for Objects
- Why does typeof array with objects return “object” and not “array”? [duplicate]
- How to add an object to an array
- Convert string in dot notation to get the object reference [duplicate]
- Filter array of objects with another array of objects
- Find and remove objects in an array based on a key value in JavaScript
- Using jQuery to compare two arrays of Javascript objects
- JavaScript equivalent of jQuery’s extend method
- jQuery: How to get the event object in an event handler function without passing it as an argument?
- How to get the hours difference between two date objects? [duplicate]
- JavaScript error (Uncaught SyntaxError: Unexpected end of input)
- How do I remove javascript validation from my eclipse project?
- syntax error: unexpected token
- break array of objects into separate arrays based on a property
- Nested JSON objects – do I have to use arrays for everything?
- How can I convert a jQuery object to an Element?
- JQuery .hasClass for multiple values in an if statement
- Find object having maximum value for the `id` property in an array of objects
- How to check null objects in jQuery
- How can I prevent text/element selection with cursor drag
- Flatten a javascript object to pass as querystring
- Does jQuery internally convert HTML5 data attribute keys to lowercase?
- Using JQuery to Access a New Window’s DOM
- Javascript “window.open” code won’t work in Internet Explorer 7 or 8
- jquery ajax parse response text
- Concatenate string with ternary operator in javascript [duplicate]