JavaScript Clone Objects & Arrays


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. Object.prototype.clone = function () {var o = new Object(); for (var property in this) {o[property] = typeof (this[property]) == 'object' ? this[property].clone() : this[property]} return o}
  2.  
  3. Array.prototype.clone = function () {var a = new Array(); for (var property in this) {a[property] = typeof (this[property]) == 'object' ? this[property].clone() : this[property]} return a}

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.