for( var i =0;i<arr.length;i++ ){ var index = arr[i].indexOf(':'); sum += parseInt( arr[i].substr(index+1,2) ); }
3 回答
已采纳

慢l慢
TA贡献22条经验 获得超3个赞
第一句,循环的条件;
第二句,把“:”首次出现的位置赋值给index;
第三句,同sum =sum+parseInt( arr[i].substr(index+1,2) ),其中arr[i].substr(index+1,2) 把字符串中“:”出现之后两个字符取出来,parseInt( arr[i].substr(index+1,2) )把取出来的两个字符转换成数字类型以用于计算。

添加回答
举报
0/150
提交
取消