Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object unpacking assignment operation?

Is there anything like this in JavaScript? Basically, I'm looking for something along these lines:

let obj_a = {test: "one", property: "two"};
let obj_b = {test: "1", other: "three"};
let obj_b ...= obj_a; // would be the equivalent of obj_b = {...obj_b, ...obj_a}

Is there builtin syntax for something like that, or is this the best I'm going to get in ES6?

like image 719
Maurdekye Avatar asked Nov 20 '25 19:11

Maurdekye


1 Answers

Object.assign would do.

let obj_a = { test: "one", property: "two" },
    obj_b = { test: "1", other: "three" };

Object.assign(obj_b, obj_a);

console.log(obj_b);
like image 198
Nina Scholz Avatar answered Nov 22 '25 08:11

Nina Scholz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!