This article to share is JS in the string conversion in the array of strings, the conversion of the function of the string, very simple and practical, the need for small partners can refer to.
Array spin string
1.join () method
?
| 1 2 3 4 |
var s= ["A", "D", "a", "F", "G", "F", "s", "G"]; S.join ()//"A,d,a,f,g,f,s,g" S.join ("")//"A D a f g f S G" s.join (")"; Adafgfsg |
Array of strings
1.call () method
?
| 1 2 3 |
var str = "ADAFGFSG"; var Strarr = Array.prototype.slice.call (str,0); Console.log (Strarr); |
Result: ["a", "D", "a", "F", "G", "F", "s", "G"]
2. Regular expressions
?
| 1 2 3 4 5 6 |
var str = "ADAFGFSG"; var Strarr = str.replace (/(.) (?=.) /g, ' $ '). Split (', '); Console.log (Strarr); var str = "ADAFGFSG"; var Strarr = Str.match (/w/g); Console.log (Strarr); |
Result: ["a", "D", "a", "F", "G", "F", "s", "G"]
3. Direct use of Split () method
?
| 1 2 3 |
var str = "ADAFGFSG"; var Strarr = Str.split ('); Console.log (Strarr); |
Result: ["a", "D", "a", "F", "G", "F", "s", "G"]
The above mentioned is this article all summarizes the content, hoped everybody can like.