在使用jQuery数组值的总和 [英] Sum of values in an array using jQuery
本文介绍了在使用jQuery数组值的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含一些值的数组,我希望得到他们的总和。这里是例子:
I have an array containing some values and I want to get their sum. Here is the example:
var somearray = ["20","40","80","400"];
我想总结使用jQuery这些值。在本实施例的结果将是540
I want to sum these values using jQuery. In this example the result would be 540.
推荐答案
您不需要jQuery的。您可以使用为
循环做到这一点:
You don't need jQuery. You can do this using a for
loop:
var total = 0;
for (var i = 0; i < someArray.length; i++) {
total += someArray[i] << 0;
}
相关阅读:
- How to go through an array and add their values
这篇关于在使用jQuery数组值的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文