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
How to assign the output of a Fetch call to a variable (JavaScript)

I try to connect the output of a Fetch call to my page variable, but I just cannot seem to do it. Could you please check out the code underneath and help me out?

enter image description here

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

I think the async/await approach will solve your issues.

async outputvariable() {
  try {

     const response = await fetch('https://api2.online-conve', {
         method: 'GET',
         credentials: 'same-origin'
     });
      const rlt = await response.json();
      return rlt;
  } catch (error) {
   console.error(error);
  }
}
about 4 years ago · Juan Pablo Isaza Report

0

You will have to make the surrounding function an async function, and then await the response.

async function(){
    try{
        var outputVariable = await fetch("URL").text();
        // Use outputVariable
    } catch(e){
        console.log('error', e);
    }
}
about 4 years ago · Juan Pablo Isaza Report

0

Or you can use the axios instead of the fetch.

import axios from 'axios';

const response = await axios('https://api2.online');

console.log(response.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!