summing numbers stored in an array in JavaScript

前端 未结 1 1573
北海茫月
北海茫月 2021-01-24 03:11

I want to sum a list of numbers stored in a JavaScript object. The object is created and updated using this code:

var myscore = $(\'input[name=\"Points1\"]\').va         


        
相关标签:
1条回答
  • 2021-01-24 04:05

    If you push() to scorelist, I'd be tempted to say it's likely an Array.

    You could use reduce().

    var total = scorelist.reduce(function(total, score) {
        return total + +score;
    }, 0);
    
    0 讨论(0)
提交回复
热议问题