I read you can delete an array element like this: How to delete an element at a certain index in an array?

I was wondering if I can do it this way too:

  function playerUnjoins() {
    address[] newActivePlayers;
    for (uint32 index; index < activePlayers.length; index++) {
      if(msg.sender == activePlayers[index])
    activePlayers.length = newActivePlayers.length;
    activePlayers = newActivePlayers;

This is shorter and looks more readable. activePlayers is an array of address stored in the blockchain.


Is it possible? I get this warning: enter image description here

When I write it with address[] memory newActivePlayers; I get (in https://ethereum.github.io/browser-solidity/#version=soljson-v0.4.2+commit.af6afb04.js):

Untitled:94:9: Error: Member "push" is not available in address[] memory outside of storage.


Your Answer

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

Browse other questions tagged or ask your own question.