remove unwanted commas in JavaScript

后端 未结 9 1627
青春惊慌失措
青春惊慌失措 2020-12-14 13:14

I want to remove all unnecessary commas from the start/end of the string.

eg; google, yahoo,, , should become google, yahoo.

If pos

9条回答
  •  醉话见心
    2020-12-14 13:40

    Not quite as sophisticated, but simple with:

    ',google,, , yahoo,, ,'.replace(/\s/g, '').replace(/,+/g, ',');
    

提交回复
热议问题