I want to implement a Loop on ImportJson()
but it doesn't work without return
The Code from this github link :ImportJson Into Google Sheets I made a new function
This's Work but it prints only 1 API call for sure because of return
function ImportData1() {
veunueid_arr = ["KovZpZA7AAEA", "KovZpa2gne"];
for (var Veunue_id1 = 0; Veunue_id1 < 2; Veunue_id1 ) {
var url = "https://app.ticketmaster.com/discovery/v2/events.json?venueId= " veunueid_arr[Veunue_id1] "&apikey=" API_key "&locale=*";
// console.log("Veuneid" Veunue_id Venue_Id_List.length);
console.log("ImportData1();" Venue_Id_List.length);
return ImportJSON (url, "/_embedded/events/name", "noInherit,noTruncate,rawHeaders" );
}
}
This's doesn't work because I didn't use return
!
So It should print the data even without Return but it doesn't
function ImportData1() {
veunueid_arr = ["KovZpZA7AAEA", "KovZpa2gne"];
for (var Veunue_id1 = 0; Veunue_id1 < 2; Veunue_id1 ) {
var url = "https://app.ticketmaster.com/discovery/v2/events.json?venueId= " veunueid_arr[Veunue_id1] "&apikey=" API_key "&locale=*";
// console.log("Veuneid" Veunue_id Venue_Id_List.length);
console.log("ImportData1();" Venue_Id_List.length);
ImportJSON (url, "/_embedded/events/name", "noInherit,noTruncate,rawHeaders" );
}
}
CodePudding user response:
I assume you want to join results from several urls in one big list. You can use Array.concat, like this
function ImportData1() {
veunueid_arr = ["KovZpZA7AAEA", "KovZpa2gne"];
var results = [];
for (var Veunue_id1 = 0; Veunue_id1 < 2; Veunue_id1 ) {
var url = "https://app.ticketmaster.com/discovery/v2/events.json?venueId= " veunueid_arr[Veunue_id1] "&apikey=" API_key "&locale=*";
results = results.concat(ImportJSON(url, "/_embedded/events/name", "noInherit,noTruncate,rawHeaders" ));
}
return results;
}