Con JavaScript, ¿cómo puedo eliminar la última coma, pero solo si la coma es el último carácter o si solo hay espacios en blanco después de la coma? Este es mi codigo. Tengo un violín de trabajo . Pero tiene un error.
var str = 'This, is a test.';
alert( removeLastComma(str) ); // should remain unchanged
var str = 'This, is a test,';
alert( removeLastComma(str) ); // should remove the last comma
var str = 'This is a test, ';
alert( removeLastComma(str) ); // should remove the last comma
function removeLastComma(strng){
var n=strng.lastIndexOf(",");
var a=strng.substring(0,n)
return a;
}