DEV Community

Discussion on: Best way to copy an object in JavaScript?

Collapse
 
ptasker profile image
Peter Tasker

That does indeed look like a good solution if you know the object props.

But JSON.parse( JSON.stringify( obj ) );, though hacky, is much quicker to write!

Collapse
 
foresthoffman profile image
Forest Hoffman

Oh okay. I misunderstood, I thought you were avoiding using that JSON.parse( JSON.stringify( obj ) ); for some reason. Whoops!

Have a good Turkey day, or a good Thursday.