Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

iterate loop over mapping in solidity

// 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 by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #iterate #loop #mapping #solidity
ADD COMMENT
Topic
Name
9+5 =