Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

162
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda