Home >Web Front-end >JS Tutorial >How to convert js arrays and strings to each other

How to convert js arrays and strings to each other

巴扎黑
巴扎黑Original
2016-11-25 15:22:361089browse

1. Convert array to string

You need to concatenate the array elements into a string with a certain character. The sample code is as follows:

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

2. Convert string to array

The implementation method is to convert the string by a certain character The characters are cut into several strings and returned in the form of an array. The sample code is as follows:

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


Statement:
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