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

97
Views
How can I get a and b out of the array?

I'm pretty new to programming, I was trying to built an API call that I will use in another function but I'm stuck here. I need to get a and b separately and as value out of this:

import axios from "axios";

async function main() {
  await axios
    .get('https://api.blocknative.com/gasprices/blockprices?confidenceLevels=99', {
      headers: {
        Authorization: 'key'
      },
    })
    .then(function(response) {
      const a = response.data.blockPrices[0].estimatedPrices[0].maxFeePerGas;
      const b = response.data.blockPrices[0].estimatedPrices[0].maxPriorityFeePerGas;
      return [a, b]
    });
};

main().catch(console.error);

How can I do it? I already take a look at scope,block and destructuring but I really can't figure a way out. Thanks for your help!

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

0

Let the main function return the promise and on resolve of that promise you will get a and b

import axios from "axios";

function main() {
  return await axios.get(
    "https://api.blocknative.com/gasprices/blockprices?confidenceLevels=99",
    {
      headers: { Authorization: "key" },
    }
  );
}
main()
  .then(function (response) {
    const a = response.data.blockPrices[0].estimatedPrices[0].maxFeePerGas;
    const b =
      response.data.blockPrices[0].estimatedPrices[0].maxPriorityFeePerGas;
    return [a, b];
  })
  .catch(console.error);

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!