es6字符串模板相互转化

1、数组转化为字符串join()

let arr=["a","r","r"];
let string = arr.join(',');
console.log(typeof(string))//String
console.log(typeof(string),string)//"a,r,r"

2、字符串转为数组split()

let string = 's,t,r,i,n,g';
let arr = string.split(',')
console.log(typeof(arr))//Array
console.log(arr)//["s","t","r","i","n","g"]

你可能感兴趣的:(es6)