loading...

re: How to Deep Clone an Array in JavaScript VIEW POST

TOP OF THREAD FULL DISCUSSION
re: how would you code the recursion example without using map?
 

If you want/need to not use ES6 stuff you would simply use a standard for loop.


// Old javascript

function cloneDeeply(arrayToClone) {

  var newArray = [];

  for (var i = 0; i < arrayToClone.length; i++) {

    if (arrayToClone[i].isArray) {
      cloneDeeply(arrayToClone[i])
    }
    else {
      newArray.push(arrayToClone[i])
    }
  }

  return newArray;
}

// Then to use it

var clone = cloneDeeply(yourArrayToCloneGoesHere);

I didn't test this or anything btw just writing an example off of the top of my head, so no promises lol

Code of Conduct Report abuse