Skip to content

Instantly share code, notes, and snippets.

Created March 30, 2020 16:41
What would you like to do?
pragma solidity ^0.6.0;
contract MyContract {
// Arrays
uint[] public uintArray = [1,2,3];
string[] public stringArray = ['apple', 'banana', 'carrot'];
string[] public values;
uint[][] public array2D = [ [1,2,3], [4,5,6] ];
function addValue(string memory _value) public {
function valueCount() public view returns(uint) {
return values.length;
Copy link

Hi, I did as exactly to your coding. But when I try to add value to the array2D. It shows error. What did I do wrong on this part? Appreciate for your answer

Copy link

callezenwaka commented May 4, 2022

The code below works fine.

 function addArray2D(uint[] memory _array) public {
      // append to array2D

function getArray2D(uint index1, uint index2) public view returns(uint) {
    // get element at specific index
    return array2D[index1][index2];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment