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

Conversion method between js array and string_javascript skills

WBOY
Release: 2016-05-16 16:42:13
Original
1167 people have browsed it

Many friends who are familiar with js have encountered the situation of converting arrays and strings in js. This article will briefly introduce this. The examples are as follows:

1. Convert array to string

You need 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. Convert string to array

The implementation method is to cut the 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
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!