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])
newActivePlayers.push(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.
Question
Is it possible? I get this warning:
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.
newActivePlayers.push(activePlayers[index]);
^-------------------^