I have to add multiple key-value pairs to an object.
I have an object called hello.
I know I have to do this to add key-value pairs to hello:
hello['a'] = 1;
hello['b'] = 2;
hello['c'] = 3;
The result will be hello = {'a':1, 'b':2, 'c':3}
I know we can do this to declare variables:
let [a,b,c] = [1,2,3];
In this case a=1, b=2, c=3
Is there an easy way like declaring variables to add key-value pairs to the object?
I know this is an error:
hello['a', 'b', 'c'] = [1,2,3]
Is there a one-line way to add key-value pairs to an object?
Object.assign(hello, {'a':1, 'b':2, 'c':3});?hello['a'] = 1;hello['b'] = 2;hello['c'] = 3;is one line