Follow by Email

Thursday, 29 August 2013

Remove starting and ending comma from variable in javascript

Below Regex(Regular Expression) should help:

var edited = test.replace(/^,|,$/g,'');
^, matches the comma at the start of the string and ,$ matches the comma at the end ..

Enjoy :)


Post a Comment


Design by Abhinav Ranjan Sinha