title: Why can't I make a copy of this 2d array in JS? How can I make a copy?
body: <p>I'm implementing a John Conway Game of Life, but I'm having a weird problem. Here is a short version if the code giving me trouble:</p>
  
  <pre><code>let lifeMap = [
    [true, false, false],
    [false, false, false],
    [false, false, false]
  ];
  let oldLifeMap = lifeMap.slice();
  for (let row = 0; row &lt; lifeMap.length; row++) {
    for (let val = 0; val &lt; lifeMap[row].length; val++) {
      let bool = lifeMap[row][val];
      let newBool = false; // here is where I would determine if cell is alive/dead
      lifeMap[row][val] = newBool;
      if (row === 0 &amp;&amp; val === 0) console.log("at (0,0)", oldLifeMap[0][0]);
    }
  }
  </code></pre>
  
  <p>In response to this code, JavaScript prints <code>at (0,0) false</code>. I need it to stay <code>true</code> until the next generation starts. </p>
  
  <p>I thought doing <code>let oldLifeMap = lifeMap.slice()</code> would fix it, but it doesn't, and I'm not sure why. (Shouldn't it <em>copy</em> the 2d array and not create a second ref to it?)</p>
  
  <p>Anyway, what is going on here, and how do I successfully make an actual copy of <code>lifeMap</code> here?</p>