Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
Get Request should return stringify value and assign to a variable

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.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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)
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!