Timeline for answer to How to use a variable for a key in a JavaScript object literal? by JamesTheAwesomeDude
Current License: CC BY-SA 4.0
Post Revisions
4 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Nov 13, 2020 at 20:19 | history | edited | JamesTheAwesomeDude | CC BY-SA 4.0 |
deprecate
|
| Nov 9, 2020 at 6:41 | comment | added | Ramil Shavaleev | The answer can be rewritten as var myNewObj = (function (myKey, myValue) { o = {}; o[myKey] = myValue; return o; })(myKey, myValue); for support versions < ES6 | |
| Jul 2, 2020 at 14:45 | comment | added | Sebastian Simon |
Arrow functions and computed property names were introduced at the same time. Your console check is incorrect, as you need to type ({ [myKey]: myValue }) into the console to make it an object, not a block. "It takes just one line" — Sure, the entire minified jQuery library takes just one line. "non-invasive" — not true if the object has getters, setters, or is a Proxy target.
|
|
| Jan 11, 2020 at 1:46 | history | answered | JamesTheAwesomeDude | CC BY-SA 4.0 |