-2

I have a value as "SPAS1_4_2" under which SPAS is fixed. I want to fetch the value 4 and 2 under different variable. these value can change based on a click however the _ will remain same.

How can I get 4 and 2 value in seprate variable

Tushar
  • 85,780
  • 21
  • 159
  • 179
Running Rabbit
  • 2,634
  • 15
  • 48
  • 69
  • 2
    First thing, the question does not show any search efforts to a _very_ simple problem. Second, there are many possible answers so **Too Broad**. – Tushar Nov 18 '15 at 10:43

1 Answers1

0

You can split your string using

var str = 'SPAS1_4_2';

var pieces = str.split('_');

document.write('Pieces: ' + pieces + '</br>');
document.write('Pieces[1]: ' + pieces[1] + '</br>');
document.write('Pieces[2]: ' + pieces[2]);
Thaillie
  • 1,362
  • 3
  • 17
  • 31
GreyRoofPigeon
  • 17,833
  • 4
  • 36
  • 59