Place the following  javascript method in your file.

String.prototype.reverse = function () 
      return this.split('').reverse().join('');
;

String.prototype.replaceLast = function (what, replacement) 
      return this.reverse().replace(new RegExp(what.reverse()),                                                replacement.reverse()).reverse();
;

invoke like below:

var name = "Sandeep, G,"
name = name.replaceLast( ',' , '' );

console.log (name); // Sandeep, G   Prints on webconsole (ctrl+shft+j) 

Enjoy !!

Advertisements