Two custom implementations of the string and the array of conversion of the JS function, hope to be useful to everyone:
Copy Code code as follows:
function StringToArray (STR,SUBSTR) {
/* Function function: strings are converted to arrays according to the specified string partition
Parameters:
STR: string to convert
SUBSTR: Split string
return value:
The converted Array
*/
var arrtmp = new Array ();
if (substr== "") {
Arrtmp.push (str);
return arrtmp;
}
var i=0, j=0, k=str.length;
while (i<k) {
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 function: Array converted to string based on split character (string)
Parameters:
Arr: Array of strings to convert
STR: Split string
return value:
Converted String
*/
var strtmp = "";
for (Var i=0;i<arr.length;i++) {
if (arr[i]!= "") {
if (strtmp== "") {
strtmp = Arr[i];
} else {
strtmp = strtmp + str + arr[i];
}
}
}
return strtmp;
}
Specific applications can refer to the relevant articles in the cloud-dwelling community.
The JavaScript array uses the Call method rollup
Http://www.jb51.net/article/13084.htm
Practical tips for JavaScript array manipulation
Http://www.jb51.net/article/19987.htm