-1

hi im a newbie and i have a problem with for loops. my code is here

async function claims(epoch) {
  let epochs = [];
  for (let i = 0; i < 10; i++) {
    rounds = epoch - i;
    const claimable = await contract.claimable(rounds, Account);
    const refundable = await contract.refundable(rounds, Account);
    (claimable || refundable) === true ? epochs.push(rounds) : 0
    console.log(epochs);
  }
}
claims()

But when I run this function, I get the following response:

[100]
[100,99]
[100,99]
[100,99,90]
[100,99,90]
[100,99,90,86]

how can i bring only last row ?

[100,99,90,86]

1
  • 2
    Move the console.log() outside the loop if you want the total, not just what each iteration does.. Although just logging the result seems not very useful, you probably want to return the value. Commented Jul 27, 2024 at 11:34

1 Answer 1

0

Move the console.log(epochs) line outside the loop. This way, the function will finish all its checks and add all the numbers to the list before printing it. You'll then see only the final list as output.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.