Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

reinitialise or reset all values in mapping in solidity

// 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 by ethereum.stackexchange.com #
 
PREVIOUS NEXT
Tagged: #reinitialise #reset #values #mapping #solidity
ADD COMMENT
Topic
Name
4+8 =