Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
72
rated 0 times [  74] [ 2]  / answers: 1 / hits: 40565  / 13 Years ago, tue, may 10, 2011, 12:00:00

i have the below variable in javascript. i want to remove the starting and ending comma sign using jquery/javascript



var test=,1,2,3,4, <--- 

Expected output: var test=1,2,3,4


please advice


More From » jquery

 Answers
23

Regex should help



var edited = test.replace(/^,|,$/g,'');


^, matches the comma at the start of the string and ,$ matches the comma at the end ..


[#92310] Monday, May 9, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
leog

Total Points: 225
Total Questions: 113
Total Answers: 118

Location: Oman
Member since Wed, Apr 12, 2023
1 Year ago
;