Here are my methods:
function RequestGet(options, url){
fetch(url, options).then(function(response){
return response.json();
}).then(function(value) {
data = JSON.stringify(value)
console.log(data)
}).catch(function() {
console.log("fail")
})
}
function GetUUID(){
data = RequestGet()
uuid = []
data2 = data.results[0].groups
groupLength = data2.length
for (i = 0; i < groupLength; i++){
uuid[i] = data2[i].uuid
}
uuidString = uuid.toString()
console.log(uuidString)
}
I need RequestGet to return the output of 'data' (which I'm able to view with console.log(data)) so I can use the dictionary in the GetUUID function below to get a specific key (key I'm looking for is uuid).
I just need to be able to pass the GET response to the GetUUID method.
Currently it returns "Undefined"
Thanks.
You need to return a Promise from your RequestGet. Try this:
function RequestGet(options, url){
return fetch(url, options).then(function(response){
return response.json();
}).then(function(value) {
data = JSON.stringify(value)
console.log(data)
return data;
}).catch(function() {
console.log("fail")
})
}
async function GetUUID(){
data = await RequestGet()
uuid = []
data2 = data.results[0].groups
groupLength = data2.length
for (i = 0; i < groupLength; i++){
uuid[i] = data2[i].uuid
}
uuidString = uuid.toString()
console.log(uuidString)
}