DEV Community

Discussion on: Making a basic deepCopy function in JS

Collapse
 
ky1e_s profile image
Kyle Stephens

It's not pretty, but it works:

const deepCopy = JSON.parse(JSON.stringify(objectToCopy));
Enter fullscreen mode Exit fullscreen mode
Collapse
 
lakbychance profile image
Lakshya Thakur

you don't say

Collapse
 
ky1e_s profile image
Kyle Stephens

?

Thread Thread
 
lakbychance profile image
Lakshya Thakur

It’s a joke man πŸ˜…. I know parse, stringify works. It’s fast too. Actually, one of my friends got this asked in an interview and thus this article.

Collapse
 
jsnanigans profile image
Brendan Mullins

I would prefer this all day to that chunky angorithm, is there any reason this is worse?