Тримивать запятую в JavaScript
let myString = "string,with,trailing,comma,";
// remove the last character of the string (regardless of what it is)
myString.substr(0, myString.length-1)
// remove only a comma if it appears at the end of the string
myString.replace(/,$/, "");
DenverCoder1