Two custom js functions for converting strings and arrays, I hope they can be useful to everyone:
function StringToArray(str,substr) {
/* Function function: The string is divided and converted into an array according to the specified string
Parameters:
str: required Converted string
substr: Split string
Return value:
Converted array
*/
var arrTmp = new Array();
if(substr==" ") {
arrTmp.push(str);
return arrTmp;
}
var i=0, j=0, k=str.length;
while(i
j = str.indexOf(substr,i);
if(j!=-1) {
if(str.substring(i,j)!="") { arrTmp.push( str.substring(i,j)); }
i = j 1;
} else {
if(str.substring(i,k)!="") { arrTmp.push(str. substring(i,k)); }
i = k;
}
}
return arrTmp;
}
function ArrayToString(arr,str) {
/* Function: Convert array to string according to splitting characters (string)
Parameters:
arr: String array to be converted
str: Split string
Return value:
Converted string
*/
var strTmp = "";
for(var i=0;iif(arr[i]!=" ") {
if(strTmp=="") {
strTmp = arr[i];
} else {
strTmp = strTmp str arr[i];
}
}
}
return strTmp;
}
For specific applications, please refer to the relevant articles of Script House.
Javascript array usage call method summary
http://www.jb51.net/article/13084.htm
Practical tips for javascript array operations
http://www.jb51.net/article/19987.htm