欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

去掉字符串空格

程序员文章站 2024-01-20 17:46:40
...
var str = "14, 19, 23, 25, 61, 6, 3, 31, 15, 31, 3, 18, 12, 61, 4, 5, 14, 11, 2, 26, 24, 6, 2, 1, 14, 11, 8, 6, 6, 2, 12, 27, 51, 22, 25, 24, 28, 3, 61, 22, 81, 26, 61, 1, 23, 11, 2, 26, 27, 11, 17, 29, 12, 14, 19, 5, 19, 24, 41, 16, 16, 41, 27, 22, 9, 91, 21, 41, 5, 29, 4, 7, 15, 27, 17, 81, 7, 9, 71, 8, 21, 19, 12, 17, 8, 13, 51, 9, 7";

str = str.split(",")

var result = "";
for(var i = 0; i < str.length; i++){

    var c = str[i].trim();
   
    if(i == 0){
        result += c;
    }else{
        c = "," + c;
        result += c;
    } 
}

console.log(result);