There are 3 arrays provided below which I have no control over:
groups_array = [ {
"group" : "Mobile Test Region",
"id" : "251"
}, {
"group" : "Mobile Demo Region",
"id" : "252"
} ]
locations_array = [ {
"location" : "M Testing",
"id" : "1376"
}, {
"location" : "Trade Show Machine",
"id" : "1403"
}, {
"location" : "M Trailer",
"id" : "1471"
}, {
"location" : "Test Los Angeles",
"id" : "1475"
} ]
pairs_array = [ {
"location_id" : "1376",
"group_id" : "251"
}, {
"location_id" : "1475",
"group_id" : "251"
}, {
"location_id" : "1403",
"group_id" : "252"
}, {
"location_id" : "1471",
"group_id" : "252"
} ]
The following code snippet is used to loop through the pairs_array and fetch the location_id's related to the group id. Upon running this code, it outputs 2 location ID's based on the given groupid stored in e.rowData.groupid.
for (var s = 0; s < pairs_array.length; s++) {
if (e.rowData.groupid === pairs_array[s].group_id) {
Ti.API.info(pairs_array[s].location_id);
}
}
I intend to compare the strings and retrieve the location names by using the location_id's obtained from the IF statement. Would it be beneficial to push the results into an array and then loop through both the location_array and the results for comparison purposes? If so, could you provide a useful code example since my previous attempts did not yield the desired output.