我有以下字符串。
18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,99,102,105,108,111,114,117,120,123,126,129,132,135,138,141,144,147
我想获取每5个数字并从字符串中删除 如果从18到30开始,则18到30将从此字符串中删除现在的字符串,如
33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,99,102,105,108,111,114,117,120,123,126,129,132,135,138,141,144,147
-
var allval = jQuery('.implodearrayhide').val();
var str_split = allval.split(",");
我正在尝试此代码,但没有用户在5
后循环完成时如何删除5号答案 0 :(得分:2)
你可以这样使用Array.filter
:
var split = allval.split(",").filter(function(i) {
return i % 5 === 0;
});
答案 1 :(得分:1)
我猜您正在寻找slice
:
> str = "18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,99,102,105,108,111,114,117,120,123,126,129,132,135,138,141,144,147"
> newstr = str.split(",").slice(5).join()
"33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,99,102,105,108,111,114,117,120,123,126,129,132,135,138,141,144,147"
答案 2 :(得分:0)
答案 3 :(得分:0)
var str = "18,21,24,27,30,33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,99,102,105,108,111,114,117,120,123,126,129,132,135,138,141,144,147";
while (str.length > 0) {
str = str.replace(str.split(",", 5).join(), "").replace(/^,/, "");
console.log(str);
}
33,36,39,42,45,48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,99,102,105,108,111,114,117,120,123,126,129,132,135,138,141,144,147
48,51,54,57,60,63,66,69,72,75,78,81,84,87,90,93,96,99,102,105,108,111,114,117,120,123,126,129,132,135,138,141,144,147
63,66,69,72,75,78,81,84,87,90,93,96,99,102,105,108,111,114,117,120,123,126,129,132,135,138,141,144,147
78,81,84,87,90,93,96,99,102,105,108,111,114,117,120,123,126,129,132,135,138,141,144,147
93,96,99,102,105,108,111,114,117,120,123,126,129,132,135,138,141,144,147
108,111,114,117,120,123,126,129,132,135,138,141,144,147
123,126,129,132,135,138,141,144,147
138,141,144,147
<强> JSfiddle 强>