I have code like this.
var key = \"anything\"; var object = { key: \"key attribute\" };
I want to know if there is a way to rep
In ES6, use computed property names.
const key = "anything"; const object = { [key]: "key attribute" // ^^^^^ COMPUTED PROPERTY NAME };
Note the square brackets around key. You can actually specify any expression in the square brackets, not just a variable.
key