Need to do a right trim on ajax query in javascript?

后端 未结 1 1533
梦毁少年i
梦毁少年i 2021-01-28 10:52

In JavaScript, I wanted to do the right trim for all the special characters at the end of the string. My Piece of code doing the trim for hyphen (-) only..Need for all the speci

相关标签:
1条回答
  • 2021-01-28 11:27

    This should do the trick.

    var x = "abcde#$@asbd#$^@$";
    x.slice(0,x.search(/\W*$/));
    

    This will only trim off the special characters at the end of the string. It will leave special characters that are in the body of the string.

    0 讨论(0)
提交回复
热议问题