Javascript to get diagonals of matrix array
<p>I want to get all the diagonals of a matrix array using javascript. Supposing the input and output as follows:</p>

<pre><code>input = [
  [1,2,3],
  [4,5,6],
  [7,8,9],
]

output = [
  [1],
  [4,2],
  [7,5,3],
  [8,6],
  [9],
]
</code></pre>

<p>How can I turn the input into the output? How can I do this so that it will work for any size square grid (2x2, 3x3, 4x4, etc.)?</p>

<p>Thanks!</p>