美文网首页
js字符串与数组转化

js字符串与数组转化

作者: jxc1 | 来源:发表于2019-03-20 16:49 被阅读0次

    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
    

    相关文章

      网友评论

          本文标题:js字符串与数组转化

          本文链接:https://www.haomeiwen.com/subject/sartvqtx.html