What is the most efficient JavaScript loop to use for this scenario?
I need to make API calls for each value in the array, which could potentially contain more values than what's shown below. After researching different types of loops and Promise.all, I'm unsure which approach to take. Example
// API Call 1. ABC
// API Call 2. DEF
// API Call 3. GHI
// API Call ....
// Input format example [ABC, DEF, GHI, ... ...]
var alp = "ABC, DEF, GHI";
var letters = alp.split(',');
var array = [letters];
// API Request
var apiRequest = http.request({
'endpoint': 'site',
'path':'/api/test/table/records',
'method': 'POST',
"headers": {
"Authorization": "Basic xxxxxxxxxxx=",
"Content-Type": "application/json"
}
});
var data = {};
var dept = {};
// Switch naming
switch (letters[0]) {
case 'ABC':
site = "A B.C";
break;
case 'DEF':
site = "D E.F";
break;
case 'GHI':
site = "G H.I";
break;
}
var u_department = dept;
data.u_department = u_department;
var apiResponse = apiRequest.write(data);
Where should I insert this code block?
var data = {};
var site = {};
switch (letters[0]) {
case 'ABC':
site = "A B.C";
break;
case 'DEF':
site = "D E.F";
break;
case 'GHI':
site = "G H.I";
break;
}
var u_department = site;
data.u_department = u_department;
var apiResponse = apiRequest.write(data);