In JavaScript, you can use the split() method to convert a string into an array. This method can split a string into a string array and return it. The syntax format is "string.split(separator, required Returns the length of the array)".
The operating environment of this tutorial: Windows 7 system, ECMAScript version 5, Dell G3 computer.
javascript converts string to array
var str="How are you doing today?"; var arr=str.split(" "); console.log(arr);
Output:
[Recommended learning: js basic tutorial】
Introduction to related functions:
split() method is used to split a string into a string array. This method can specify two parameters. The first parameter is the separator, specifying where to separate the mark; the second parameter specifies the length of the array to be returned. The syntax is as follows:
string.split(separator,limit)
Return value: a string array. The array is created by splitting the string string Object into substrings at the boundaries specified by separator. The strings in the returned array do not include the separator itself.
For more programming related knowledge, please visit: Programming Video! !
The above is the detailed content of How to convert string to array in javascript. For more information, please follow other related articles on the PHP Chinese website!