___ ___ Do erkimt the cumulative value in the loop ______ qstntxt ___
%pre%

I need to get the next value adding the former to have a build-up.

    
______ ___ azszpr325514
%pre%

To add integers use the parseInt function. Full Example:

%pre%     
___

1
var previsto = [];
for(var i = 0; i < $(".previsto").length ; i++)
{ 
    previsto[i] =  $(".previsto").eq(i).text();
}

I need to get the next value adding the former to have a build-up.

    
asked by anonymous 28.08.2018 / 16:02

1 answer

1
___ ___ Do erkimt the cumulative value in the loop ______ qstntxt ___
var previsto = [];
for(var i = 0; i < $(".previsto").length ; i++)
{
    if(i == 0)
      previsto[i] =  $(".previsto").eq(i).text();
    else
      previsto[i] =  previsto[i-1] + $(".previsto").eq(i).text();
}

I need to get the next value adding the former to have a build-up.

    
______ ___ azszpr325514
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>eq demo</title>
  <style>
  div {
    width: 60px;
    height: 60px;
    margin: 10px;
    float: left;
    border: 2px solid blue;
  }
  </style>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script></head><body><div>20</div><div>4</div><script>varprevisto=[];for(vari=0;i<$("div").length ; i++)
{
    if(i == 0)
      previsto[i] =  parseInt($("div").eq(i).text());
    else
      previsto[i] =  parseInt(previsto[i-1]) + parseInt($("div").eq(i).text());

}
console.log(previsto);
</script>
</body>
</html>

To add integers use the parseInt function. Full Example:

var previsto = [];
for(var i = 0; i < $(".previsto").length ; i++)
{
    if(i == 0)
      previsto[i] =  $(".previsto").eq(i).text();
    else
      previsto[i] =  previsto[i-1] + $(".previsto").eq(i).text();
}
    
___
28.08.2018 / 16:10