Place the following  javascript method in your file.

// Keep this in common js of your project
String.prototype.reverse = function () {
      return this.split('').reverse().join('');
};
// Keep this as well in common js of your project
String.prototype.replaceLast = function (what, replacement) {                                 
      return this.reverse().replace(new RegExp(what.reverse()),                   replacement.reverse()).reverse(); };


var name = "Sandeep, G," name = name.replaceLast( ',' , '' ); 
// Just invoke name.replaceLast where-ever is required.
 console.log (name); 
// Sandeep, G   Prints on webconsole (ctrl+shft+j)  

Concept behind the replaceLast java script method is very simple here,

  1. before applying replace method ; reverse both pattern & its replacement.
  2. after replacement reverse the result.

Enjoy !!