What is the most efficient way to deep clone an object in JavaScript?
Asked 07 September, 2021
Viewed 1.8K times
  • 60
Votes

What is the most efficient way to clone a JavaScript object? I've seen obj = eval(uneval(o)); being used, but that's non-standard and only supported by Firefox.

I've done things like obj = JSON.parse(JSON.stringify(o)); but question the efficiency.

I've also seen recursive copying functions with various flaws.
I'm surprised no canonical solution exists.

30 Answer