let str = "Testing, how to, remove, comma"
How can I remove that last comma (,) between "remove" and "comma" using JavaScript? Preference using replace with regex
let str = "Testing, how to, remove, comma"
How can I remove that last comma (,) between "remove" and "comma" using JavaScript? Preference using replace with regex
There are probably better ways than using regular expressions, but you can do this:
str.replace(/,([^,]+$)/, "$1")
const str = "Testing, how to, remove, comma"
console.log(str.replace(/,([^,]+$)/, "$1"));
The regular expression matches a comma, then in a group it matches everything that is not a comma until the end of the string. The replacement is "$1", which is the first capturing group, meaning everything after the last comma.