javascriptjqueryvariablessubstrtexttrimming

Trim a variable's value until it reaches to a certain character


so my idea is like this..

var songList = ["1. somesong.mid","13. abcdef.mid","153. acde.mid"];
var newString = myString.substr(4); // i want this to dynamically trim the numbers till it has reached the .

// but i wanted the 1. 13. 153. and so on removed. // i have more value's in my array with different 'numbers' in the beginning

so im having trouble with this can anyone help me find a more simple solution which dynamically chop's down the first character's till the '.' ?


Solution

  • You can do something like

    var songList = ["1. somesong.mid","13. abcdef.mid","153. acde.mid"];
    songList.forEach(function(value, i){
        songList[i] = value.replace(/\d+\./, ''); //value.substr(value.indexOf('.') + 1)
    });
    

    Demo: Fiddle