Below is how I do the record into the mapping array. How can I create a clear|removeall function that clears or reset all the records back to default which is empty?
address payable[] public players;
mapping(address => uint256[]) playerTicket;
function playersRecord() public view returns(uint256[] memory){
return playerTicket[msg.sender];
}
I managed with the below function to clear one by one but not sure how to clear all
function remove(address _addr) public {
// Reset the value to the default value.
delete playerTicket[_addr];
}
You cannot clear all mapping values without specificy the key.
Thus, Solidity doesn't know the keys of the mapping. Since the keys are arbitrary and not stored along, the only way to delete values is to know the key for each stored value.
Your remove()
function is correct to clear the values of a specific mapping key.
More information here.