trim comma in javascript

Solutions on MaxInterview for trim comma in javascript by the best coders in the world

showing results for - "trim comma in javascript"
Klara
10 Apr 2019
1let myString = "string,with,trailing,comma,";
2
3// remove the last character of the string (regardless of what it is)
4myString.substr(0, myString.length-1)
5
6// remove only a comma if it appears at the end of the string
7myString.replace(/,$/, "");