I have a string that is like below.
,liger, unicorn, snipe,
how can I trim the leading and trailing comma in javascript?
In ECMAScript 5 and above, you can now do a one-liner
',liger, unicorn, snipe,'.split(',').map(e => e.trim()).filter(e => e).join(', ')