Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ECMAScript5 deep copy of object and arrays

I'd hope to find an example code to do a deep copying of objects in ECMAScript5.

The copying should be able to clone

  • Nested objects

  • Nested arrays

  • Nested objects in arrays (clone each array item individually)

Note: jQuery.extend() does not seem to handle case 3). Also, I'd hope to do this in clean ECMAScript. Quick googling did not bring up any worthy implementations.

like image 828
Mikko Ohtamaa Avatar asked Dec 23 '25 03:12

Mikko Ohtamaa


1 Answers

I finally settled to jQuery.extend() as I couldn't find other good implementations

http://api.jquery.com/jQuery.extend/

like image 57
Mikko Ohtamaa Avatar answered Dec 24 '25 15:12

Mikko Ohtamaa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!