Javascript Array deepClone()

Description

Javascript Array deepClone()

Array.prototype.deepClone = function () {
  var arrClone = [];

  _.each(this, function(innerObj) {
    if (Array.isArray(innerObj)) {
      arrClone.push(innerObj.deepClone());
    } else {//from w  w  w .j  a v  a 2 s  .c om
      arrClone.push(_.clone(innerObj));
    }
  });

  return arrClone;
};

Javascript Array deepClone()

/**/*  www  .  ja  va2  s . co m*/
 * Creates deep copy of arrays
 *
 * @returns {*}
 */
Array.prototype.deepClone = function () {
  return JSON.parse(JSON.stringify(this));
};



PreviousNext

Related