-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
  • 82,599
  • 19
  • 151
  • 169
Running Rabbit
  • 2,432
  • 15
  • 42
  • 65
  • 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,332
  • 3
  • 16
  • 30
LinkinTED
  • 17,122
  • 4
  • 31
  • 55