Is there a short-hand to do the following:
let o = {}
o['a'] = 1;
o['b'] = 2;
For example, either:
let o = {}
o.update({'a': 1, 'b': 2})
Or:
let o = {'a': 1, 'b': 2}
CodePudding user response:
Object.assign
can achieve it.
const o = { original: 'orig' };
Object.assign(o, {'a': 1, 'b': 2});
console.log(o);