'array.length--; show TypeError, what can I use instead of that to have no empty gap in array after deleting?
TypeError: Member "length" is read-only and cannot be used to resize arrays.
It's solidity 0.8;
uint[] public array;
function removeElement(uint i) public {
array[i] = array[array.length-1];
delete array[array.length-1];
array.length--;
}
Solution 1:[1]
Problem solve array.pop(), it deletes last element and resizes array (decrements by 1)
should be used array.pop();
instead of:
array.length--;
and delete array[array.length-1] is redundant
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
