Js array and string conversion method

  • 2020-03-30 03:32:29
  • OfStack

Many friends familiar with js have encountered js array and string conversion, this article is a simple introduction, the example is as follows:

Array to the string

Array elements need to be concatenated with a character into a string. The sample code is as follows:


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

Two, string to array

The method is to cut the string into several strings by a certain character and return them as an array. The sample code is as follows:


var s = "abc,abcd,aaa";
ss = s.split(",");//  At each comma (,) I'm going to decompose. 

Related articles: