How can I remove the last comma in my for loop?

前端 未结 6 1194
伪装坚强ぢ
伪装坚强ぢ 2021-01-26 18:54
function currentLine(katzDeliLine) {
    if (katzDeliLine.length > 0) {
        var textToPrint = \"The line is currently: \"

        for (var crrLine = 0; crrLine &         


        
6条回答
  •  情深已故
    2021-01-26 19:07

    You can use regex to remove the last comma

    $ is for matching the end of the string

    let line = 'string1, string2, string3, string4, string5,'
    
    console.log(line.replace(/,$/g,''))

提交回复
热议问题