জাভাস্ক্রিপ্ট ব্যবহার করে, আমি কীভাবে শেষ কমাটি সরিয়ে ফেলব তবে কমা যদি শেষ চরিত্র হয় বা কমা পরে কেবলমাত্র সাদা স্থান থাকে? এটি আমার কোড। আমি একটি কাজের ভারসাম্য পেয়েছিলাম । তবে এটি একটি বাগ আছে।
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;
}