Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript for循环内部的数组之和_Javascript_Jquery_Arrays - Fatal编程技术网

Javascript for循环内部的数组之和

Javascript for循环内部的数组之和,javascript,jquery,arrays,Javascript,Jquery,Arrays,我试图得到for循环中每个数组的和。 我现在的代码是这样的 for (var i = 1; i < 6; i++) { (function(i) { if ($(".brand_name-"+i).length > 0 ) { Array_new = parseInt ($(".price-" + i).text()); someArray = $

我试图得到for循环中每个数组的和。 我现在的代码是这样的

for (var i = 1; i < 6; i++) {
    (function(i) {
        if ($(".brand_name-"+i).length > 0 ) {
            
            Array_new = parseInt ($(".price-" + i).text());
            someArray = $.trim (Array_new);
            var total = 0;
            for (var k = 0; k < someArray.length; k++) {
                total += someArray[k] << 0;
            }

            console.log(total);
        }
for(变量i=1;i<6;i++){
(职能(一){
如果($(“.brand_name-”+i).length>0){
Array_new=parseInt($(“.price-”+i.text());
someArray=$.trim(Array\u new);
var合计=0;
for(var k=0;k
合计
使用

const ELS_price=document.queryselectoral(“.product_price_send”);
//const ELS_prod_price=$(“.product_price_send”).get();//如果使用jQuery
const sum=[…ELS_价格]。减少((tot,el)=>{
tot+=数字(el.textContent.trim());
返回tot;
}, 0);
console.log(总和)
88.87
8.78

48.78
我想他希望price-5和price-3分别相加。
Array\u new=parseInt($(.price-“+I.text());
是的,分别感谢@Anuga、price-5和price-3
<strong class="product_price_send price-3">88.87</strong>
<strong class="product_price_send price-5">8.78</strong>
<strong class="product_price_send price-5">48.78</strong>