es6字符串模板相互轉化

一、數組轉化爲字符串join()數組

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

二、字符串轉爲數組split()code

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"]
相關文章
相關標籤/搜索