Summing array on Javascript

前端 未结 5 1965
死守一世寂寞
死守一世寂寞 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 04:09

    Try this one:

    var total = 0;
    for (var i = 0; i < someArray.length; i++) {
        total += someArray[i] << 0;
    }
    

提交回复
热议问题