美文网首页
多行文本变数组

多行文本变数组

作者: 织雪纱奈 | 来源:发表于2019-04-18 17:04 被阅读0次
var lines = "line1 2  221\n\
                     line2  22 3232\n\
                     line3  2332  2332";

        function A(text){
            let arr = text.split('\n')
            arr.forEach( function(element, index) {
                 let cc = element.replace(/\s+/g,'$').split('$');
                 cc.forEach( function(element, index) {
                    if(element ===''){
                        cc.splice(index,1)
                    }
                 });
                 arr[index] = cc
            });
            return arr
        }

        A(lines)

相关文章

网友评论

      本文标题:多行文本变数组

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