Skip to content

Instantly share code, notes, and snippets.

@josemvcerqueira
Created October 1, 2022 19:37
Show Gist options
  • Select an option

  • Save josemvcerqueira/b9d5fdc693a2060b14f242f96d5c900c to your computer and use it in GitHub Desktop.

Select an option

Save josemvcerqueira/b9d5fdc693a2060b14f242f96d5c900c to your computer and use it in GitHub Desktop.
Array in Array example
pragma solidity >=0.8.9;
contract Test {
uint256[][20] public array;
mapping(uint256 => bool) private _exists;
function push(uint256 index, uint256 indexChildren, uint256 value) external {
bool exists = _exists[index];
if (!exists) {
uint256[] memory newArray = new uint256[](20);
array[index] = newArray;
_exists[index] = true;
}
uint256[] memory storedArray = array[index];
storedArray[indexChildren] = value;
array[index] = storedArray;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment