How to split an array using commas and how to apply each split strings as params in Postman?

I saved the following country code in environment variables and now I need to take each one from the country code and put it in the URL. The reason is that I need to call the same URL for 200 countries and I was able to retrieve all country codes and save them in environment variables. I do not know how to split the country code with commas and how to apply the parameters to the URL

Environment variable screenshot:

Country codes saved as array in the environment variable AA,UZ,UY,GH,TV,GG,TT,GL,TZ,GI,TW,GN,UG,GM,UA,US,UM,FO,TJ,FM,TH,GA,TL,FR,TK,GD,TN,GB,TM,GF,TR,GE,TO,TF,TD,TG,FK,SS,FJ,SR,SV,ST,SY,SX,TC,SZ,EE,SI,EC,SH,EH,SK,EG,SJ,ES,SM,ER,SL,FI,SO,ET,SN,SG,DM,RU,DK,RS,DZ,SA,DO,RW,SC,SB,SE,SD,CV,PS,CU,PR,CX,PW,CW,PT,CZ,QA,CY,PY,DJ,RO,DE,RE,PM,PL,PN,CR,OM,CO,NZ,PE,PA,PG,PF,PK,PH,CG,NG

Need to apply each country code end of this URL like US

Using the below code I set to environment -
pm.test(“Get code of each countries”, function () {
var jsonData = pm.response.json();
pm.environment.set(“variable_key”, jsonData.map((value) => value.code));
});

Can you please help me how to split the country and how to apply in the params?

HI,
If you are filling the Variable_key as string, then may be try applying the string method

const country_codes = text.split(" ,");
let code = country_codes[1];

Apply the loop if you want to pass all the country codes.

Hope this helps

regards
Sowmya

Thanks @sowmya101 for your quick response. How to apply each country code in the url ?
https://{{vaultDNS}}/api/v22.2/app/medical/opendata/reference-types/HCPType?country=US

Like US, I want to send this request to all country code ?

Your response would be appreciated

You can make use of

         postman.setNextrequest("loop your query parameter")

To come out of the loop, pass null
postman.setNextRequest(null)

Thanks @sowmya101
I really don’t know why setNextrequest doesn’t work. Can you please help me with this?

pm.test("Get code of each countries", function () {
var jsonData = pm.response.json();
    pm.environment.set("variable_key", jsonData.map((value) => value.code));

});

var country_code = pm.environment.get("variable_key".split(","));

for (var i = 0; i < country_code.length; i++) {
    pm.environment.set("code", country_code[i]);
         postman.setNextRequest("Endpoint/country=" + country_code[i]);
}
postman.setNextRequest(null);

pm.test("Status code is 200", function () {
    pm.response.to.have.status(200);
});
    

Thanks in advance