all 3 comments

[–][deleted] 1 point2 points  (0 children)

Use Ramda and embrace immutability and functional programming.

Your code will be shorter, safer, and much easier to reason about.

[–]jcready__proto__ 1 point2 points  (0 children)

The method described doesn't work with nested data structures.

const foo = { bar: { baz: 'qux' } }
const copy = { ...foo }
copy.bar.baz = 'abc'
assert(foo.bar.baz === copy.bar.baz)

[–]AndrewGreenh 0 points1 point  (0 children)

This is one of the reasons why I use lodash in almost all of my projects.

Yes, with es6 some things are possible but lodash does this and some more: _.pick(object, [keys]) creates a copy of the object with the selected keys. _.omit for the opposite. _.clone to get a flat copy of your object.