I have dynamic array of matches as:
[
"Rivers United - Kano Pillars",
"MFM FC - Abia Warriors",
"Lobi Stars - Enugu Rangers",
"Sunshine Stars - Dakkada",
"Ifeanyi Ubah - Kwara United",
"Enyimba - Adamawa United",
"Empoli - Torino U19",
"Bologna U19 - Ascoli",
"Lazio - Inter U19",
"Juventus U19 - Spal",
"Milan - Fiorentina U19",
"Sassuolo U19 - AS Roma U19",
"Genclerbirligi - Denizlispor",
"Goztepe - Fenerbahce",
"Kayserispor - Demir Grup Sivasspor",
"Trabzonspor U19 - Istanbul Basaksehir AS",
"Fatih Karagumruk - KASIMPASA AS",
"Portugal - Israel",
"Wydad AC Casablanca - DHJ ",
"Rsb Berkane - Athletic Youssoufia"
]
When I perform API call using supertest library based on above array, I am able to fetch single opponent and keep into a single variables and my code is:
const response = await api.getRequestAsync("https://sports/api/feeds/prematch/mostpopularsports/en/1/5/6/", `2021-06-06`, "", "");
const otp = api.jsonPath(response.body, `$[0].AreaMatches[0].Items..ItemName`);
let opponent1 = otp[0].split(" - ")[0];
let opponent2 = otp[0].split(" - ")[1];
let opponent20 = otp[5].split(" - ")[1];
console.log(opponent1 + " | " + opponent2 + " | " + opponent20);
which produces variables as: opponent1, opponent2...opponent20
and console output as: [0-0] Rivers United | Kano Pillars | Adamawa United
But this creates manual work to assign value to every single variable.
How can I transfer this code to loop logic, so dynamically will have variable for every single opponent: Rivers United, Kano Pillars...Athletic Youssoufia
and variables as: opponent1, opponent2...opponent20