📜  重新初始化或重置 Solidity 映射中的所有值 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:36.637000             🧑  作者: Mango

代码示例1
// 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;
    }
}