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

How to convert string into array in javascript

王林
Release: 2021-10-26 17:01:29
Original
15477 people have browsed it

How to convert a string into an array in JavaScript: 1. Cut the string into several strings according to a certain character; 2. Return it in the form of an array, such as [var s = "abc,abcd,aaa "; ss = s.split(",");].

How to convert string into array in javascript

#The operating environment of this article: windows10 system, javascript 1.8.5, thinkpad t480 computer.

Friends who have studied JavaScript should have encountered the situation of converting arrays and strings. Today I will share the method of converting arrays and strings, as follows:

1. Converting an array to a string

Needs to concatenate the array elements into a string using a certain character. The sample code is as follows:

var a, b;
a = new Array(0,1,2,3,4);
b = a.join("-");
Copy after login

2. Converting a string to an array

Implementation method In order to cut a string into several strings according to a certain character and return it in the form of an array, the sample code is as follows:

var s = "abc,abcd,aaa";
ss = s.split(",");// 在每个逗号(,)处进行分解。
Copy after login

Recommended learning: javascript video tutorial

The above is the detailed content of How to convert string into 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