Home > Web Front-end > JS Tutorial > body text

How to convert string to array in js

WJ
Release: 2020-05-30 16:48:14
Original
4197 people have browsed it

How to convert string to array in js

#How to convert string to array in js?

The js string to array function is "split()", its usage is as follows

string.split(separator,limit)
Copy after login

Parameter value

ParametersDescription
separator Optional. A string or regular expression to split the string Object from where specified by this parameter.
limit Optional. This parameter specifies the maximum length of the returned array. If this parameter is set, no more substrings will be returned than the array specified by this parameter. If this parameter is not set, the entire string will be split regardless of its length.

First create a new index.html file and add the following code:

<!DOCTYPE html>
<html lang="en">
<head> 
<meta charset="UTF-8"> 
<title>m.sbmmt.com 字符串转换成数组</title>
 <script> var str="abcdefg" //1、将字符串转成数组形式:split() 
 var arr=str.split("") 
 console.log(arr)//["a", "b", "c", "d", "e", "f", "g"] 
 </script>
 </head
 ><body>
 </body>
 </html>
Copy after login

Then run the index.html file in the browser and view the console

How to convert string to array in js

Related references: JS Tutorial

The above is the detailed content of How to convert string to array in js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
js
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