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

How to convert string to array in javascript

青灯夜游
Release: 2023-01-03 09:31:51
Original
6623 people have browsed it

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);
Copy after login

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)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template