Iterate Loop Over Mapping In Solidity

[Solved] Iterate Loop Over Mapping In Solidity | Solidity - Code Explorer | yomemimo.com
Question : iterate loop over mapping in solidity

Answered by : anxious-alligator-bx1nkddr8shy

// Answer 1
// initialise a counter and an mapping in addition to the mapping you intend to iterate over
uint counter; // you should initialize this to 0 in the constructor
// the value in the countToAddress mapping points to the key in the next mapping
mapping (uint => address) private countToAddress;
// intend to iterate over the addressToValue mapping:
mapping (address => uint) private addressToValue;
function iterateOverAddressToValue() public { uint currentValue; for (uint i=0; i < counter; i++) { currentValue = addressToValue[countToAddress[i]]; }
}

Source : https://stackoverflow.com/a/48912304/10261711 | Last Update : Sun, 19 Dec 21

Answers related to iterate loop over mapping in solidity

Code Explorer Popular Question For Solidity