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

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

angryTom
angryTomOriginal
2020-03-04 17:35:559261browse

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"]

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!

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