title: Changing an Array That Was Sliced From Another Array, Changes the Original Array
body: <p>So I'm trying to copy an array to another array so that I can make changes to it without changing the original. Normally I would just use Array.prototype.slice() but I'm using a multidimensional array and it doesn't seem to be working.
  So for example:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>   let arrayOne = ["zebra", "elephant", "lion"];
  let arrayTwo = arrayOne.slice();
  
  arrayTwo[1] = "whale";
  console.log(arrayOne);</code></pre>
  </div>
  </div>
  </p>
  
  <p>should output ["zebra", "elephant", "lion"] as if the original array has remained untouched and it does. At the same time:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>        
          let arrayOne = [];
  for (let a = 0; a &lt; 4; a += 1) {
    arrayOne.push([]);
    for (let b = 0; b &lt; 4; b += 1) {
      arrayOne[a].push({itemOne: "success"});
    }
  }
  
  let arrayTwo = [];
  for (let c = 0; c &lt; 4; c += 1) {
    arrayTwo.push([]);
    for (let d = 0; d &lt; 4; d += 1) {
   arrayTwo[c] = arrayOne[c].slice();
    }
  }
  
  arrayTwo[3][1].itemOne = "failure";
  console.log("It should be a " + arrayOne[0][0].itemOne);
  console.log("and it has been a " + arrayOne[3][1].itemOne);</code></pre>
  </div>
  </div>
  </p>
  
  <p>I'm trying to get this to output "and it has been a success" but it reads "failure". Any ideas as to why?</p>