I was wondering which was the appropriate way to reset an array to initial state, and so delete all the elements that it contains.

I found the following ways:

  1. delete paidPlayers;
  2. paidPlayers.length = 0
  3. array = new type[](0)

I understand that those are equivalent from a result point of view, however I suppose there are differences about gas usage

1 Answer 1


Solidity docs recommends using delete array

Source: https://docs.soliditylang.org/en/v0.4.23/miscellaneous.html#tips-and-tricks

Use delete on arrays to delete all its elements.

Your Answer

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