I am trying to remove a certain item of the array in solidity.
I was exploring some articles.
https://ethereum.stackexchange.com/questions/1527/how-to-delete-an-element-at-a-certain-index-in-an-array
Of course, I don't need the empty value of the item. I need to remove completely the item.
uint[] payees = [1, 2, 3, 4, 5];
delete payees[0]
// result - I don't need this result
[0, 2, 3, 4, 5]
//I need [2, 3, 4, 5]
So I have used this function.
function removePayee(
uint256 index
) internal {
if (index >= payees.length) return;
for (uint i = index; i<payees.length-1; i++){
payees[i] = payees[i+1];
}
delete payees[payees.length-1];
payees.length--;
}
The following error has occurred.
Member "length" is read-only and cannot be used to resize arrays.