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

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

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 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