I have 3 arrays as displayed below. I have no control over the arrays.
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"
} ]
Here is the code I used to loop through the pairs_array and retrieve the location_id’s that correspond with the group id. Ti.API.info(pairs_array[s].location_id); outputs 2 location ID’s based on the groupid given using 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 am trying to compare the strings and retrieve the location names using the location_id’s ive gotten from the IF statement. Should I just push the results into an array and loop through the location_array and the results and compare? If so, I’d like to see a good code snippet for that since the few times I tried I was not getting the expected output.
1 Answer