What is the most efficient way to clone a JavaScript object?
Posted
by jschrab
on Stack Overflow
See other posts from Stack Overflow
or by jschrab
Published on 2008-09-23T16:26:09Z
Indexed on
2010/03/18
12:11 UTC
Read the original article
Hit count: 327
What is the most efficient way to clone a JavaScript object? I've seen:
obj = eval(uneval(o));
but that's not cross platform (FF only). I've done (in Mootools 1.2) things like this:
obj = JSON.decode(JSON.encode(o));
but question the efficiency. I've also seen recursive copying function, etc. I'm pretty surprised that out-of-the-box JavaScript doesn't have a method for doing this.
© Stack Overflow or respective owner