How to convert string to array in js
May 30, 2020 pm 04:48 PM#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)
Parameter value
Parameters | Description |
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>www.php.cn 字符串转换成数组</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>
Then run the index.html file in the browser and view the console
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!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to use JS and Baidu Maps to implement map pan function

Essential tools for stock analysis: Learn the steps to draw candle charts with PHP and JS

Recommended: Excellent JS open source face detection and recognition project

PHP and JS Development Tips: Master the Method of Drawing Stock Candle Charts

How to create a stock candlestick chart using PHP and JS

How to use JS and Baidu Maps to implement map polygon drawing function

How to use JS and Baidu Map to implement map click event processing function

How to use JS and Baidu Maps to implement map heat map function
