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

152
Vistas
Save the value of a response in an extern variable at the

I'm new to promises and wondering how to store the result of a response in an extern variable

var obj;
fetch("https://api.nvidia.partners/edge/product/search?page=1&limit=9&locale=fr-fr&category=GPU&gpu=RTX%203070&manufacturer=NVIDIA&manufacturer_filter=NVIDIA~1,ASUS~1,EVGA~3,GIGABYTE~2,MSI~1,PNY~0,ZOTAC~0")
    .then(res => res.json())
    .then(data => obj = data.searchedProducts.featuredProduct.retailers[0].purchaseLink)
    .then(() => console.log(obj))

console.log(obj);

I manage to display the response in the promise but not outside

the undefined value comes from the second console.log

Thank you for taking the time to read my request :)

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

0

What you can do is await it:

const res = await fetch("https://api.nvidia.partners/edge/product/search?page=1&limit=9&locale=fr-fr&category=GPU&gpu=RTX%203070&manufacturer=NVIDIA&manufacturer_filter=NVIDIA~1,ASUS~1,EVGA~3,GIGABYTE~2,MSI~1,PNY~0,ZOTAC~0");
const data = await res.json();
const obj = data.searchedProducts.featuredProduct.retailers[0].purchaseLink;
console.log(obj);

Then you can just console.log() it.

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