Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

172
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda