小编dra*_*m95的帖子

如何删除模板文字中的多余空格?

当我创建模板文字时,我会使用trim() 来删除多余的空间。但我注意到,当我在 JS 函数中执行此操作时,它仍然会创建额外的制表符或空白。

  function BottlesOfBeer()  {
    
        for (i = 99; i>=1; i--) {
    
            if (i === 1) {        
                var oneBottle = "1 bottle of beer on the wall, 1 bottle of beer.\n" +
                                "Take one down and pass it around, no more bottles of beer on the wall.\n" +
                                "No more bottles of beer on the wall, no more bottles of beer.\n" +
                                "Go to the store and buy some more, 99 bottles of beer on the wall.";        
                
                console.log(oneBottle); …
Run Code Online (Sandbox Code Playgroud)

javascript string function

6
推荐指数
1
解决办法
5972
查看次数

标签 统计

function ×1

javascript ×1

string ×1