Remove first character from a string if it is a comma

前端 未结 4 1547
死守一世寂寞
死守一世寂寞 2020-12-05 09:34

I need to setup a function in javascript to remove the first character of a string but only if it is a comma ,. I\'ve found the substr function bu

4条回答
  •  难免孤独
    2020-12-05 10:04

    s = (s.length && s[0] == ',') ? s.slice(1) : s;
    

    Or with a regex:

    s = s.replace(/^,/, '');
    

提交回复
热议问题