JavaScript set object key by variable - Stack Overflow

PHOTO EMBED

Sat Feb 12 2022 20:24:31 GMT+0000 (UTC)

Saved by @dickosmad #javascript #object #key

var key = "name";
var person = {[key]:"John"}; // same as var person = {"name" : "John"}
console.log(person); // should print  Object { name="John"}
content_copyCOPY

https://stackoverflow.com/questions/11508463/javascript-set-object-key-by-variable