remove starting and ending comma from variable in javascript

后端 未结 4 1573
礼貌的吻别
礼貌的吻别 2021-02-13 04:18

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,\" <--- 

Expecte         


        
4条回答
  •  离开以前
    2021-02-13 05:10

    Regex should help

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

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

提交回复
热议问题