Often I want to construct an object with a runtime-generated key.
Here's how I have been doing it:
function make_obj(key, func, val){
let foo={};
foo[key] = func(val);
return foo;
}
Usage:
make_obj('food', x=>`I like ${x}`, 'soup'); // {food: 'I like soup'}
Is there a shorter way to do this?
{[key]: func(val)}to create an object literal with a dynamically keyed property. \$\endgroup\$