Home >Web Front-end >JS Tutorial >JS function to split string and put into array_javascript skills

JS function to split string and put into array_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:05:031505browse
复制代码 代码如下:

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]
);
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn