Replace first character of string

后端 未结 7 869
走了就别回头了
走了就别回头了 2020-12-05 23:01

I have a string |0|0|0|0

but it needs to be 0|0|0|0

How do I replace the first character (\'|\') with (\'\'

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-05 23:55

    Try this:

    var str = "|0|0|0|0";
    str.replace(str.charAt(0), "");
    

    Avoid using substr() as it's considered deprecated.

提交回复
热议问题