Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

103
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda