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
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;
}
}
-
thank you for your response..im only trying establish single value inside of the array. How do I do that?– YannickCommented Feb 9, 2022 at 3:24
-
1
-
Yep if you're trying to append a new value to the array push() is your answer– MeriadocCommented 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– YannickCommented Feb 10, 2022 at 1:56
-