1.字符串转化为数组
var str = 'qwarasdazxav';
var arr = str.split('');
console.log(arr);// ["q", "w", "a", "r", "a", "s", "d", "a", "z", "x", "a", "v"]
var arr2 = str.split('a');
console.log(arr2);//["qw", "r", "sd", "zx", "v"]
2.数组转换为字符串
var arr = [1,2,3,4,5];
var str1 = arr.join('');
var str2 = arr.join('-');
console.log(str1+' and '+str2);//12345 and 1-2-3-4-5
网友评论