JS 数组与字符串的相互转化

1.数组转化为字符串

使用数组对象的join()方法来实现数组转化为字符串。

var a= [1,2,3,4,5];
const b = a.join();//join默认‘,’
const c= a.join('***');
console.log(b);
console.log(c);

2.字符串转化为数组

使用string对象的split()方法来实现字符串转化为数组。

var a= [1,2,3,4,5];
const b = a.join();//join默认‘,’
const c= a.join('***');
const d = c.split('***');
//d已经是一个数组了
console.log(d[2]);

 

posted @ 2020-07-02 19:12  江之鸟  阅读(304)  评论(0)    收藏  举报