naren naren - 2 months ago 5
Javascript Question

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

This is my output

9781473507340.epub,9781473518902.epub,,,,,,


i need this output

9781473507340.epub,9781473518902.epub


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

Answer

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
Comments