Remove Last Comma from a string

前端 未结 10 1151
轻奢々
轻奢々 2020-11-30 19:52

Using JavaScript, how can I remove the last comma, but only if the comma is the last character or if there is only white space after the comma? This is my code. I got a wor

10条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-30 20:06

    Remove last comma. Working example

    function truncateText() {
      var str= document.getElementById('input').value;
      str = str.replace(/,\s*$/, "");
      console.log(str);
    }
    
    

提交回复
热议问题