2

I wanna split in this code and store it in three different variables, like a=GD11, b=GDP7 and c=GD11, but I have problem that break in "s" shows result of "GDP7xGD11".

How can I break in separated three variables please help and suggest me.

var someString = "GD11sGDP7xGD11";
var lastWord = someString.split("s").pop();
alert(lastWord);
Rodia
  • 1,407
  • 8
  • 22
  • 29
faizan
  • 45
  • 3

1 Answers1

2

Use regular expression /[sx]/

It will produce an array as follows.

var someString = "GD11sGDP7xGD11";
        var lastWord = someString.split(/[sx]/);
      console.log(lastWord);

To sotre it in variable,

var someString = "GD11sGDP7xGD11";
var lastWord = someString.split(/[sx]/);
a=lastWord[0];
b=lastWord[1];
c=lastWord[2];
console.log(a,b,c);
Sagar V
  • 12,158
  • 7
  • 41
  • 68