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

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

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