Question : reinitialise or reset all values in mapping in solidity
Answered by : anxious-alligator-bx1nkddr8shy
// example mapping:
mapping(address => uint256) investments;
// you have to have an list storing the addresses in order to iterate over the mapping
address [] investers;
// function to reset all values in the mapping to {value}
function resetBalance(uint256 value)public { // iterate over the array to iterate over the mapping and reset all to value for (uint i=0; i< investers.length ; i++) { investments[investers[i]] = value; }
}
Source : https://ethereum.stackexchange.com/a/68836/86303 | Last Update : Mon, 13 Dec 21