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(/,$/, "");