Home > Web Front-end > JS Tutorial > What is the method to convert string to array in JavaScript?

What is the method to convert string to array in JavaScript?

angryTom
Release: 2020-03-04 17:35:55
Original
9452 people have browsed it

What is the method to convert string to array in JavaScript?

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"]
Copy after login

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"]
Copy after login

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!

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