String.prototype.replaceLastOccurrence = function(search, replace) {
return this.replace(new RegExp(search + "([^" + search + "]*)$"), replace + "$1");
}
let str = 'c c++, javascript, python, php';
str = str.replaceLastOccurrence(",", "");
console.log(str);
/*
run:
"c c++, javascript, python php"
*/