Home  >  Article  >  Web Front-end  >  How to convert string to array in javascript

How to convert string to array in javascript

青灯夜游
青灯夜游Original
2021-03-30 15:37:306568browse

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)".

How to convert string to array in javascript

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:

How to convert string to array in javascript

[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)

How to convert string to array in javascript

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn