title: javascript - create array with foreach loop through table
body: <p>i have a form with table like this:</p>
  
  <pre><code>&lt;table id="preview"&gt;
  &lt;tbody&gt;
  &lt;tr&gt;
  &lt;td&gt;01/01/2010&lt;/td&gt;
  &lt;td&gt;Credit&lt;/td&gt;
  &lt;td&gt;1000&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;01/05/2010&lt;/td&gt;
  &lt;td&gt;Debit&lt;/td&gt;
  &lt;td&gt;200&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;01/09/2010&lt;/td&gt;
  &lt;td&gt;Debit&lt;/td&gt;
  &lt;td&gt;400&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;01/11/2010&lt;/td&gt;
  &lt;td&gt;Debit&lt;/td&gt;
  &lt;td&gt;100&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>Now I need to create an array to send (ajax/php) like this:</p>
  
  <pre><code>$ajaxArray = array(   0 =&gt; array(From   =&gt; "01/01/2010",  //1st td of the 1st Row
                                      To     =&gt; "01/05/2010",  //1st td of the 2nd Row
                                      Type   =&gt; "Credit",
                                      Amount =&gt; 1000.00),
                           1 =&gt; array(From   =&gt; "01/05/2010",  //1st td of the 2nd Row
                                      To     =&gt; "01/09/2010",  //1st td of the 3th Row
                                      Type   =&gt; "Debit",
                                      Amount =&gt; 200.00),
                           2 =&gt; array(From   =&gt; "01/09/2010",  //1st td of the 3th Row
                                      To     =&gt; "01/11/2010",  //1st td of the 4th Row
                                      Type   =&gt; "Debit",
                                      Amount =&gt; 400.00),
                           3 =&gt; array(From   =&gt; "01/11/2010",  //1st td of the 4th Row
                                      To     =&gt; "01/01/2012",  //Value in $last_date var
                                      Type   =&gt; "Debit",
                                      Amount =&gt; 100.00)
          );
  </code></pre>
  
  <p>I tried with this code:</p>
  
  <pre><code> $('#preview &gt; tbody  &gt; tr').each(function() {
              var from = $('td:eq(0) ', this).text();
              var type = $('td:eq(1) ', this).text();
              var amount = $('td:eq(2) ', this).text();
              ajaxArray.push({
                  From: from,
                  Type: type,
                  Amount: amount
              });
          });
  </code></pre>
  
  <p>As you can see i can't get the "To" date value. The "To" date value is the date contained in the 1st TD of the Next row except for the last Row, where this value is in the $last_date variable.</p>
  
  <p>Thanks in advance</p>