I need to get the next value adding the former to have a build-up.
I need to get the next value adding the former to have a build-up.
To add integers use the parseInt function. Full Example:
%pre%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.
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.
<!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();
}