title: push data in Array AJAX/NodeJS
body: <p>When I selected a service from select input, I got a div created by JS as below:</p>
  <pre><code>&lt;form method=&quot;POST&quot; action=&quot;/booking/success&quot;&gt;
  // SOME CODE IN HERE.................................
  &lt;div class=&quot;col-12&quot;&gt;
        &lt;h3 class=&quot;service__title&quot; name=&quot;serviceTitle&quot;&gt;Service 1&lt;/h3&gt;
        &lt;p&gt;&lt;span class=&quot;display__number&quot;&gt;1&lt;/span&gt; x &lt;span&gt;500&lt;/span&gt;&lt;/p&gt;
        &lt;p&gt;&lt;b class=&quot;display__total&quot;&gt;500&lt;/b&gt;&lt;/p&gt;
  &lt;/div&gt;
  &lt;div class=&quot;col-12&quot;&gt;
        &lt;h3 class=&quot;service__title&quot; name=&quot;serviceTitle&quot;&gt;Service 2&lt;/h3&gt;
        &lt;p&gt;&lt;span class=&quot;display__number&quot;&gt;1&lt;/span&gt; x &lt;span&gt;1500&lt;/span&gt;&lt;/p&gt;
        &lt;p&gt;&lt;b class=&quot;display__total&quot;&gt;1500&lt;/b&gt;&lt;/p&gt;
  &lt;/div&gt;
  &lt;button type=&quot;submit&quot; class=&quot;btn btn-right&quot; id=&quot;submitBtn&quot; &gt;&lt;span&gt;SUBMIT  &lt;/span&gt;&lt;i class=&quot;fas fa-paper-plane&quot;&gt;&lt;/i&gt;&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  <p>I create Ajax variable for using in Nodejs:</p>
  <pre><code>&lt;script&gt;
    &lt;script&gt;
      $(&quot;button[type='submit']&quot;).click(function (){
          var length = $('.service__title').length;
          var data = [];
          alert($('.service__title:eq(0)').text());
          alert(parseInt($('.display__number:eq(0)').text()));
          for(let i = 0; i &lt; length; i++){
              data.push({
                  title: $('.service__title:eq(i)').text(),
                  quantity: parseInt($('.display__number:eq(i)').text()),
                  subtotal: parseInt($('.display__total:eq(i)').text())
              })
          }
          $.ajax({
              async:false,
              url: &quot;../booking/success&quot;,
              type: &quot;POST&quot;,
              dataType: &quot;html&quot;,
              data: {data:data},
              contentType: &quot;application/x-www-form-urlencoded&quot;,
          })
              
      });
  
  &lt;/script&gt;
  </code></pre>
  <p>and console log:</p>
  <pre><code>app.post('/booking/success', async (req,res)=&gt; {
      console.log(req.body);
      console.log(req.body.data);
      res.render(&quot;success&quot;);
  })
  </code></pre>
  <p>When I clicked Submit, my array &quot;data&quot; is undefined.</p>
  <pre><code>{ data: 
  [ { title: '  ', quantity: 'NaN', subtotal: 'NaN' } ] 
  [ { title: '  ', quantity: 'NaN', subtotal: 'NaN' } ]
  </code></pre>
  <p>Please help me!</p>