Given the following example. Is there a shorthand for the field asignment
let myObj = {someField: 'someValue'}
let foo = 'value'
myObj.foo = foo // I would like to do the opposite of object destructuring: const {foo} = myObj. I don't want to repeat foo twice.
You could use Object.assign
with a short hand property.
const myObj = {}
const foo = 'value'
Object.assign(myObj, { foo });
console.log(myObj);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With