title: Pushing array into array then handling elements inside
body: <p>so I just came across this, but could anyone explain it to me, why is this phenomenon present here? I didn't find any help online...</p>
  <p>1.So if I were to get the following two arrays:</p>
  <pre><code>let a = [];
  let b = ['','',''];
  </code></pre>
  <p>2.and then push array <code>b</code> into array <code>a</code> three times:</p>
  <pre><code>a.push(b);
  a.push(b);
  a.push(b);
  </code></pre>
  <p>3.but then when I try to change the first element of the first array like so:</p>
  <pre><code>a[0][0] = 'foo';
  </code></pre>
  <p>4.then all the first element of ALL the arrays change, not just the first one, as <code>console.log(a)</code> outputs:</p>
  <pre><code>(3) [Array(3), Array(3), Array(3)]
  0: Array(3)
    0: &quot;foo&quot;
    1: &quot;&quot;
    2: &quot;&quot;
  
  1: Array(3)
    0: &quot;foo&quot;
    1: &quot;&quot;
    2: &quot;&quot;
  
  2: Array(3)
    0: &quot;foo&quot;
    1: &quot;&quot;
    2: &quot;&quot;
  </code></pre>
  <p>I would like to ask, why does this happen and in what way could I change an element based on its index inside of array <code>a</code></p>