0

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 '.' ?

Adarsh Hegde
  • 623
  • 2
  • 7
  • 19

2 Answers2

0

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

Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
  • no sorry i didn't make this clear.. i wanted to have the number's including the . cut out from the variable but i have variable's with different lengths so i wanted to find a more dynamic way of removing them – Adarsh Hegde Mar 09 '15 at 03:28
  • @AdarshHegde I think it does that `newString` will have a value of ` sometext.mp3` is that what you needed – Arun P Johny Mar 09 '15 at 03:31
  • sorry that was the point i didn't be specific.. i should edit this question and have some more details. – Adarsh Hegde Mar 09 '15 at 03:33
0

You can use the string .match() method to extract the part up to and including the first . as follows:

var newString = myString.match(/[^.]*./)[0];

That assumes that there will be a match. If you need to allow for no match occurring then perhaps:

var newString = (myString.match(/[^.]*./) || [myString])[0];

If you're saying you want to remove the numbers and keep the rest of the string, then a simple .replace() will do it:

var newString = myString.replace(/^[^.]*. */, "");
nnnnnn
  • 147,572
  • 30
  • 200
  • 241