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

143
Views
Extract the value out of a promise

I'm trying to extract information from a Promise returned by a fetch call. I don't seem to be able to do this. Either I get an undefined or I get another Promise, rather then the actual content of the promise itself. For example:

     async function fetchCoordinates(pluscode) {
       let response = await fetch(url.replace("${pluscode}", pluscode));
       return await response.json();
     }
     
     function getCoordinates(pluscode) {
       let geoinfo;
       fetchCoordinates(pluscode).then(info => {geoinfo = info})
       return geoinfo
     }
   
     geoinfo = getCoordinates("{{ place.pluscode }}");

When evaluated, geoinfo is undefined (instead of an object). However, if I change this line:

fetchCoordinates(pluscode).then(info => {geoinfo = info})

to:

fetchCoordinates(pluscode).then(info => {console.log(info)})

Then the object is saved logged correctly to the console.

about 4 years ago · Juan Pablo Isaza
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!