remove starting and ending comma from variable in javascript

后端 未结 4 1594
礼貌的吻别
礼貌的吻别 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:15

    Below code sample will do this

            var str = ",1,2,3,4,5,6,7,8,9,";
            str = str.substring(1,str.lastIndexOf(","));
    

提交回复
热议问题