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
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
You might do as follows;
var str = "9781473507340.epub,9781473518902.epub,,,,,,", newStr = str.replace(/,*(?=$)/,""); console.log(newStr);
Could be an overkill, but you can try something like this.
These steps can be followed.
split()
based on the commas. join()
. var input = '9781473507340.epub,9781473518902.epub,,,,,,'; var output = input .split(',') //split to array .filter(function(val, b){ return val.length }) //filter out the blank items .join(','); //put the new array to a string. console.log(output);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.