If I have a text string like so:
var cadena1 = "cadena_1";
And I only need to get the 1 from the previous string to put it in a variable, how can I do it?
Doing this:
var res = cadena1.split("_");
the result iscadena,1
If I have a text string like so:
var cadena1 = "cadena_1";
And I only need to get the 1 from the previous string to put it in a variable, how can I do it?
Doing this:
var res = cadena1.split("_");
the result iscadena,1
it would suffice to do:
Cheers
You can use
split()
grabbing the second element:Or use
substring()
if you know there will only be 1 number. With the possibility of values> 9
I would use the option ofsplit()
Just use split()