naren naren - 10 months ago 44
Javascript Question

How to remove multiple comma from end of string using javascript?

This is my output


i need this output


only using dynamically get files name in javascript.It possible get dynamically

Answer Source

To remove every trailing comma, you could use this regex:

var str = "9781473507340.epub,9781473518902.epub,,,,,,";
var res = str.trim().replace(/,{1,}$/, '');
console.log(res); // 9781473507340.epub,9781473518902.epub