Home > Article > Web Front-end > How to convert string into array in javascript
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(",");].
#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("-");
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(",");// 在每个逗号(,)处进行分解。
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!