Is possible in javascript define an object field name based on the value of a variable INLINE?
for exemple:
const field = "name";
const js = {field:"rafael"};
console.log(js);
the result of this code will be {field:rafael}
but the result I want is {name:rafael}
.
I know I can do
const field = "name";
const js = {};
js[field] = "rafael";
but i would like to do inline as I initialize the object. Is that possible?