जावास्क्रिप्ट का उपयोग करते हुए, मैं अंतिम अल्पविराम कैसे निकाल सकता हूं, लेकिन केवल अगर अल्पविराम ही अंतिम वर्ण है या यदि अल्पविराम के बाद केवल सफेद स्थान है? यह मेरा कोड है। मुझे वर्किंग फील मिला । लेकिन इसका एक बग है।
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;
}