此时情绪此时天,无事小神仙
好好生活,平平淡淡每一天

编辑

Js字符串与数组互换

数组转字符串

需要将数组元素用某个字符连接成字符串

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

字符串转数组

实现方法为将字符串按某个字符切割成若干个字符串,并以数组形式返回

var s = "abc,abcd,aaa";
ss = s.split(",");// 在每个逗号(,)处进行分解  ["abc", "abcd", "aaa"]
var s1 = "helloworld";
ss1 = s1.split('');  //["h", "e", "l", "l", "o", "w", "o", "r", "l", "d"]

image

posted @ 2020-06-11 13:44  踏步  阅读(426)  评论(0编辑  收藏  举报