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

173
Vistas
How can I store the data returned from an async function
async function getDetails(country){
  let response = await fetch(`https://restcountries.com/v2/name/${country}`);
  let [data]= await response.json();
  return data
}

let portugal = getDetails('portugal');

Is there a way to store the data returned from a async function in JavaScript?

I know, the async function will always return a promise, and can use ".then(func)" to do another thing with the data. But how can i store it in a variable and use it later?

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

0

Yes you can.

let portugal = await getDetails('portugal');

If you don't use await keyword before getDetails() you will get the promise as you correctly pointed out and not the data result.

Note that await getDetails() only works when being called inside an async function.

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