JS分割字符串并放入数组的函数_javascript技巧
时间:2021-07-01 10:21:17
帮助过:3人阅读
代码如下:
var InterestKeywordListString = $("#userInterestKeywordLabel").html();
var InterestKeywordListArr = [];
var t = '';
for (var i = 0; i < InterestKeywordListString.length; i++) {
var tmp = InterestKeywordListString.charAt(i);
if (tmp != '' && tmp != ',') {
t += tmp;
lastNum = true;
} else {
if (t != '' && t != ',') {
InterestKeywordListArr.push(t);
t = '';
}
lastNum = false;
}
}
if (t != '' && t != ',') {
InterestKeywordListArr.push(t);
}
for(var i=0;ialert(
InterestKeywordListArr[i]
);
}