title: how to remove NaN from field value and show value?
body: <p>I make a dynamic form, if i delete a row then in loop result is <code>NaN</code> of the deleted element i want when i delete element its 0 value pass not <code>NaN</code>. Like i delete 5th element when 1=5 it shows <code>NaN</code>. How to remove this error and instead 0 will be add in sum value, how i do?   </p>
  
  <pre><code>$("body").on('change', '.quantity', function() {
      var that = $(this);
      if ($('#itemcounter').val()==""){
          $('#itemscounter').val("1");
          var counter=$('#itemscounter').val();
          var quantity=$('#quantity').val();
          var unitprice=$('#unitprice').val();
          var linetotal=quantity*unitprice;
          that.parent().find('.linetotal').val(linetotal) 
          $("#invoicetotalamount").val(+linetotal)
          var discount=document.getElementById('discount').value ;
          var discountamount= discount/100 * linetotal;
          var amount=linetotal-discountamount;
          $("#balanceamount").val(+amount);
  
      } else {            
          var counter=$('#itemscounter').val();
          var quantity=$('#quantity').val();
          var unitprice=$('#unitprice').val();
          var linetotal=quantity*unitprice;
          $('#linetotal').val(+linetotal);
          var sum=linetotal;
  
          for (i = 2; i &lt;=counter; i++) {
              var quantity=parseFloat($('#quantity' + i).val());
              var unitprice=parseFloat($('#unitprice' + i).val());
              var linetotal=quantity*unitprice;
              $('#linetotal' + i).val(+linetotal);
              alert(sum);         
              sum=+sum +(+(linetotal));           
          }
  
          $("#invoicetotalamount").val(+sum); 
          var discount=document.getElementById('discount').value ;
          var discountamount= discount/100 * sum;
          var amount=sum-discountamount;
          $("#balanceamount").val(+amount);
      }
  });
  </code></pre>