Posted By

iTony on 05/30/09


Tagged

javascript array Objects pointers


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

Vordreller
wizard04


Deep Copy an Array or Object


 / Published in: JavaScript
 

URL: http://james.padolsey.com/javascript/deep-copying-of-objects-and-arrays/

  1. function deepCopy(obj) {
  2. if (Object.prototype.toString.call(obj) === '[object Array]') {
  3. var out = [], i = 0, len = obj.length;
  4. for ( ; i < len; i++ ) {
  5. out[i] = arguments.callee(obj[i]);
  6. }
  7. return out;
  8. }
  9. if (typeof obj === 'object') {
  10. var out = {}, i;
  11. for ( i in obj ) {
  12. out[i] = arguments.callee(obj[i]);
  13. }
  14. return out;
  15. }
  16. return obj;
  17. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: carol2000 on June 17, 2010

great

You need to login to post a comment.