Two custom JS functions that implement mutual conversion between strings and arrays hope to be useful to you:
CopyCode The Code is as follows: function stringtoarray (STR, substr ){
/* Function: Splits a string into an Array Based on the specified string.
Parameters:
STR: string to be converted
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 <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: convert an array to a string based on the delimiter (string ).
Parameters:
Arr: String Array to be converted
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;
}
For specific applications, refer to the related topic home.Article.
Javascript array summary using call Methods
Http://www.jb51.net/article/13084.htm
Practical Tips for JavaScript Array Operations
Http://www.jb51.net/article/19987.htm