How to convert strings into arrays in javascript
This article mainly explains "how to convert strings into arrays in javascript". The explanation in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian and go deep into it slowly to study and learn "how to convert strings into arrays in javascript" together!
The method of converting a string into an array in javascript: 1. Cut the string into several strings according to a certain character;2. Return it in array form, such as [var s = "abc,abcd,aaa"; ss = s.split(",");].
Operating environment: windows 10 system, javascript 1.8.5, thinkpad t480 computer.
Small partners who have learned javascript should have encountered the case of array and string conversion, and today Xiaobian will share the method of array and string conversion, as follows:
1. Array to String
You need to concatenate the array elements into a string with a character. The example code is as follows:
var a, b;a = new Array(0,1,2,3,4);b = a.join("-");
Second, string to array
The implementation method is to cut the string into several strings according to a certain character and return them in array form. The example code is as follows:
var s = "abc,abcd,aaa";ss = s.split(",");//Split at each comma (,). Thank you for reading, the above is "javascript string how to convert to array" content, after the study of this article, I believe we have a deeper understanding of how to convert javascript string to array this problem, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!