What is the most efficient way to clone a JavaScript object?
- by jschrab
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.