mercredi 25 février 2015

Javascript selecting to save one index of split()

I have a value - toggle-save_2 I want to extract the 2 part. The part after the underscore will always be what i need but the length of the former part, which in this case is toggle-save_, may vary (eg. notoggle-val_45). Though this length may vary it will always be separated from the end number by an underscore.


Right now I am using this



var current = this.id.split('_');
current = current[1];


to select the number.


What would be cool is if I could pass a variable to the split to only give me the second index of the result from the split.


Aucun commentaire:

Enregistrer un commentaire