Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!