weibo_刺眼的光芒闭目可视_0
2015-08-07 17:31
尤其是这句 score[i] = parseInt(mystr[i].split(":")[1]);很喜欢
1、字符串scoreStr被分裂成数组mystr=["小明:87","小花:81","小红:97","小天:76","小张:74","小小:94","小西:90","小伍:76","小迪:64","小曼:76"]
2、第一次循环时,i=0,
mystr[0]="小明:87",
mystr[0].split(":")=["小明","87"]是一个数组,
mystr[0].split(":")[0] ="小明",mystr[0].split(":")[1] ="87"
而你说的mystr[0].split(":",1)只取第一个字符串,所以这个数组的长度为1,mystr[0].split(":",1)="小明"
3、所以是我错了~不好意思啊,误导你了~赶紧改正@刘荣轩1991
1、字符串scoreStr被分裂成数组mystr=["小明:87","小花:81","小红:97","小天:76","小张:74","小小:94","小西:90","小伍:76","小迪:64","小曼:76"]
2、第一次循环时,i=1,
mystr[1]="小明:87",
mystr[1].split(":")=["小明","87"]是一个数组,
mystr[1].split(":")[1] ="小明",mystr[1].split(":")[1] ="小明",mystr[1].split(":")[2] ="87"
而你说的mystr[1].split(":",1)只取第一个字符串,所以这个数组的长度为1,mystr[1].split(":",1)="小明"
3、所以这里应该改为mystr[i].split(":")[2]
求平均值不应该是Math.round(sum /(i+1))么?
split(“:”)【1】什么意思?为什么不用split(“:”,1)
JavaScript进阶篇
468060 学习 · 21891 问题
相似问题