pragma solidity ^0.4.19; contract ArrayDelete { struct ArrayItem { uint8 someUint; bool valid; } ArrayItem[] myArray; function addArrayItem(uint8 _someUint) public { myArray.push(ArrayItem(_someUint, true)); } function removeByIndex(uint8 _index) public { myArray[_index].valid = false; } function deleteByIndex(uint8 _index) public{ delete myArray[_index]; } function countValids() private returns (uint8) { uint8 counter = 0; for (uint8 i = 0; i < myArray.length; i++) { if (myArray[i].valid) { counter++; } } return counter; } function getArrayItems() public view returns (uint8[]) { uint8[] memory items = new uint8[](countValids()); uint8 counter = 0; for (uint8 i = 0; i < myArray.length; i++) { if (myArray[i].valid) { items[counter] = myArray[i].someUint; counter++; } } return items; } }
0.4.19