title: How to create nested array of different length from a multidimensional array
body: <p>I have an array that looks like this:</p>
  <pre><code>arr = [[1,2,3],
         [4,5,6],
         [7,8,9]]
  </code></pre>
  <p>I have initialized an empty array and I want put the diagonals of the arr inside the new array. So i've tried this:</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>arr = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
  ]
  new_arr = [];
  tail = arr.length - 1;
  for (let i = 0; i &lt; arr.length; i++) {
    for (let j = 0; j &lt; arr[i].length; j++) {
      if (j == i) {
        new_arr.push(arr[i][j]);
      }
      if (j == tail) {
        new_arr.push(arr[i][j]);
        tail--;
      }
    }
  }
  
  console.log(new_arr)</code></pre>
  </div>
  </div>
  </p>
  <p>The logic seems to work but I can't seem to get the structure right. What I want is to nest two arrays inside the new array like this:</p>
  <pre><code>[[1,5,9],[3,5,7]]
  </code></pre>
  <p>But what I get is one array with the right values unordered. How to get the expected output? Any help is appreciated. Thanks!</p>