r/learnjavascript • • Feb 16 '21

Javascript Object Merge

Post image
183 Upvotes

28 comments sorted by

View all comments

1

u/--Explosion-- Feb 17 '21

Nice but you can do it in one line:

let object_1 = {hello: "World"};
let object_2 = {another: "Thing"};
//Object 1 props overwrite that of object 2.
let merged = {...object_1, ...object_2};

1

u/backtickbot Feb 17 '21

Fixed formatting.

Hello, --Explosion--: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.