美文网首页工作生活
split(字符串转数组)和join(数组转字符串)

split(字符串转数组)和join(数组转字符串)

作者: 关耳木南 | 来源:发表于2019-07-04 23:40 被阅读0次
    <script type="text/javascript">
        var arr = [2,3,4,5,6];
        var str = "bacadaeaf";
        console.log(arr.join(""));//23456
        console.log(arr.join("1"));//213141516
        console.log(arr.join("1").split("1"));//["2", "3", "4", "5", "6"]
        console.log(str.split(""));//["b", "a", "c", "a", "d", "a", "e", "a", "f"]
        console.log(str.split("a"));//["b", "c", "d", "e", "f"]
        console.log(str.split("a").join("a"));//bacadaeaf
    </script>
    

    相关文章

      网友评论

        本文标题:split(字符串转数组)和join(数组转字符串)

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