Knowing the balance 

The next thing that we want to do is to cycle through the addressTransactions array to figure out what the balance of the address that we are searching for is. In order to know the balance:

  1. Let's first define a variable balance as follows: 
let balance = 0;
  1. Next, we want to cycle through all of the transactions inside of the addressTransactions array. We will do that with the help of the forEach loop as follows: 
let balance = 0;addressTransactions.forEach(transaction => { });
  1. Inside the loop, mention the conditions with the help of if and else-if statements, as follows: 
let balance = 0;addressTransactions.forEach(transaction => {        if (transaction.recipient === address) balance += transaction.amount; else if (transaction.sender ...

Get Learn Blockchain Programming with JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.