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

110
Vistas
Javascript returned data from function which fetches an api

I have the follwoing function which uses fetch to cal a restfull APi and get the output data which is in text format:

async function fetchText(url) {
            let response = await fetch(url);
            let data = await response.text();
            console.log('data...',data);
            return data;
        }

The function execution of this script

mydata=fetchText(myurl);
console.log("mydata...........",mydata);

returns this out put

mydata........... Promise[[Prototype]]: Promise[[PromiseState]]: "fulfilled"[[PromiseResult]]: ""6269A297-851B-4158-873B-66F068B73BCD"" data... "6269A297-851B-4158-873B-66F068B73BCD"

How to change the function so that its output is exactly what is displayed by the log instead of the Promise type ?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

function that uses async keyword will always returns promise, so use following code to print value.

fetchText(myurl).then(data=>{ console.log(data) })

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