Summing array on Javascript

前端 未结 5 2025
死守一世寂寞
死守一世寂寞 2021-01-28 03:41

Hi I am trying to sum an array on Javascript with the following codes.

var data[]: 
var total=0;
data.push[x]; // x is numbers which are produced dynamically. 
f         


        
5条回答
  •  情话喂你
    2021-01-28 03:54

    Use parseInt() javascript function....

    total = total + parseInt(data[i]);

    This looks the 'x' which you mention come dynamically has a string type. Just check the "typeof x".

提交回复
热议问题