Delete first character of a string in Javascript

前端 未结 14 1460
名媛妹妹
名媛妹妹 2020-11-28 01:01

I want to delete the first character of a string, if the first character is a 0. The 0 can be there more than once.

Is there a simple function that checks the first

相关标签:
14条回答
  • 2020-11-28 01:48

    Another alternative to get the first character after deleting it:

    // Example string
    let string = 'Example';
    
    // Getting the first character and updtated string
    [character, string] = [string[0], string.substr(1)];
    
    console.log(character);
    // 'E'
    
    console.log(string);
    // 'xample'
    
    
    0 讨论(0)
  • 2020-11-28 01:52
    var test = '0test';
    test = test.replace(/0(.*)/, '$1');
    
    0 讨论(0)
提交回复
热议问题