How to split Comma separated values

sk59
Tera Expert

Hi All,

I am returning multiple location values under each country like below which has comma

Country A - av, mexico

Country A - abo,vig,abanaro

I need to get these locations when a specific country is selected and display only those locations. 

As the locations include comma(,) how do I split and display

I am able to get the values like av, mexico,abo,vig,abanaro in the logs

but how do I set it in the locations field?

 

10 REPLIES 10

Aksha
Tera Guru

Hi,

if it is a string, you can try

var countryA=av, mexico;

var name=countryA.split(',');

for(var i=0;i<name.length;i++)

{

   var value=name[i];

}

 

if it is an array,

var countryA=[av,mexico];

for(var j=0;j<countryA.length;j++)

{

var value=countryA[j];

}

 

If the answer doesn't suffice , Could you please elaborate your requirement to set location?

Thanks

Service_RNow
Mega Sage

HI,

Check this website. Maybe you will find some interesting information.

Click Here

 

Please mark reply as Helpful/Correct, if applicable. Thanks!

Rahul Kumar17
Tera Guru

hi

i checked in background script

 

var countryA="abo,vig,abanaro";

var name=countryA.split(',');

for(var i=0;i<name.length;i++)

{

   gs.print(name[i]);
}

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar

Is it working?

yes it's working

If my response helped please mark it correct and close the thread.

Thanks,
Rahul Kumar