Javascript for循环内部的数组之和
我试图得到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 (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>