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

294
Visualizações
how to get the sum of data numbers inside an array

I am currently studying Vue and creating a personal account for the gazoline company.

I have an API IMG in console log inside the data array there is also a transfer array, also u can see in below picture.

enter image description here

This data is output like this :

enter image description here

I want to get the amount of income in each tankfarme. How can I do it ?

somehow I was able to get the amount of the expense, but it receives the entire amount, and not in one tankfarm. Here is code

const getSumExpense = computed(() => {
 let array = getTransfers.value.transfers.data;
 let sum = 0;
 array.forEach((element) => {
 let arrayIncome = element.transfer;

 arrayIncome.forEach((el) => {
  sum = sum + el.expense;
  });
 });

return sum;
});

please help me, if you do not understand what I wrote, also tell me, I will try to write better

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can Array.prototype.reduce()

Code:

const arrayIncome = [{expense: 20}, {expense: 30}, {expense: 40}]

const sum = arrayIncome.reduce((a, { expense: e }) => a + e, 0)

console.log(sum)

about 4 years ago · Juan Pablo Isaza Relatório

0

If you want to get the sum of some specific tankfarm then you have to filter the array first and then with the help of reduce you can sum the records.

const data= [{tankfarm: 'cymma', transfer: [{expense: 10}, {expense: 20}]}]
const result = data.filter(element => element.tankfarm === 'cymma')[0].transfer.reduce((a, { expense: e }) => a + e, 0)

console.log("cymma expense", result)

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