What is the method to convert a string to an array in JavaScript
Use to convert a string to an array in JavaScriptsplit()method.
Recommended learning: js tutorial
1. Convert according to special characters:
For example, string var str = ' abc,def,ghi'
can be converted into an array using str.split(',')
Result:
["abc", "def", "ghi"]
2. Convert into a single character array
For example, the string var str = 'abc,def,ghi'
can be converted into an array of single characters using str.split('')
Result:
["a", "b", "c", ",", "d", "e", "f", ",", "g", "h", "i"]
For more related knowledge, please pay attention to PHP Chinese website!
The above is the detailed content of What is the method to convert string to array in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!