title: How do I traverse an array diagonally in javascript
body: <p>I have an array with strings that I would like to traverse diagonally.<br>
  Assumptions:</p>
  
  <ul>
  <li>Each string is the same length.</li>
  <li>Arrays could be square or rectangular, horizontally or vertically.</li>
  </ul>
  
  <p>The matrix looks like this:</p>
  
  <pre><code>A B C D
  E F G H
  I J K L
  </code></pre>
  
  <p>I Would like to get (from top left to bottom right): </p>
  
  <pre><code>A
  EB
  IFC
  JGD
  KH
  L
  </code></pre>
  
  <p>and (from the bottom left to top right): </p>
  
  <pre><code>I
  JE
  KFA
  LGB
  HC
  D
  </code></pre>
  
  <p>I already have a piece of code that works 3/4 of the way, but i cant seem to figure out what I am doing (wrong). </p>
  
  <pre><code>//the array
  var TheArray = ['ABCD','EFGH','IJKL'];
  
  //amount of rows
  var RowLength = TheArray.length;
  //amount of colums
  var ColumnLength = TheArray[0].length;
  </code></pre>
  
  <p>The code I have chops up the diagonals into 4 of these loops to get all the diagonals. It looks as 2 for loops with an if to not loop over unbound values. The pseudo code looks a bit like this:   </p>
  
  <pre><code>for(loop rows){
   var outputarray = [];
     for(loop columns){
        if(delimit for out of bound){
         var temprow = TheArray[something?];
         var tempvalue = temprow[something?];
         outputarray.push(tempvalue);
         }
     }
   //use values
  document.getElementById("theDiv").innerHTML += outputarray.join("")+"&lt;br&gt;";
  }
  </code></pre>
  
  <p>I hope somebody can help me with this.</p>