Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140705

How can I calculate the sum of values of Plaid API transaction array in Java Script?

$
0
0

Apologies for the potentially silly question - I'm fairly new to coding/JavaScript.

I am using Plaid's sandbox environment to pull in transactional data in a sandbox environment. Right now, I define the following as transactionData:

    let transactionsData = [];
transactions.forEach(function(account) {
  account.transactions.forEach(function(transaction) {
    transactionsData.push({
      account: account.accountName,
      date: transaction.date,
      category: transaction.category[0],
      name: transaction.name,
      amount: transaction.amount
    });
  });
});

I can successfully render the individual transactions row by row in a material table like so:

    const transactionsColumns = [
  { title: "Account", field: "account" },
  { title: "Date", field: "date", type: "date", defaultSort: "desc" },
  { title: "Name", field: "name" },
  { title: "Amount", field: "amount", type: "numeric" },
  { title: "Category", field: "category" }
];

          <MaterialTable
            columns={transactionsColumns}
            data={transactionsData}
            }}

I know this has to be super simple, but all I want to do is sum the transactionsData and render that single summed value elsewhere on my page. If I write transactionsData.length I can receive the count of the transactions quite easily. I have tried the following somewhat similar syntax but have not found it to work:

array.reduce(function(total, currentValue, currentIndex, arr), initialValue)

Any help would be much appreciated.


Viewing all articles
Browse latest Browse all 140705

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>