0
pragma solidity ^0.8.0;

contract cool {
  
  uint[] public data;
  
   function set(uint _data) public {
     data = _data;
   }
  function see() public view returns(uint[] memory) {
      return data;
  }
}

1 Answer 1

0

Here is how you append a new element to the end of an array:

pragma solidity ^0.8.0;

contract cool {
  
  uint[] public data;
  
   function set(uint _data) public {
     data.push(_data);
   }
  function see() public view returns(uint[] memory) {
      return data;
  }
}
6
  • thank you for your response..im only trying establish single value inside of the array. How do I do that?
    – Yannick
    Commented Feb 9, 2022 at 3:24
  • 1
    data.push(_data); Commented Feb 9, 2022 at 3:58
  • Yep if you're trying to append a new value to the array push() is your answer
    – Meriadoc
    Commented Feb 9, 2022 at 5:00
  • now im getting member "push" not found or not visible after argument dependent lookup in uint256[] storage ref from the compiler @KostiantynKurbatskyi
    – Yannick
    Commented Feb 10, 2022 at 1:56
  • @Meriadoc reference compiler error above
    – Yannick
    Commented Feb 10, 2022 at 1:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.