Push function error in REMIX #6138
Answered
by
Nlferu
Seh-Pankaj
asked this question in
Q&A
-
Can anyone tell me what's wrong with this code. |
Beta Was this translation helpful? Give feedback.
Answered by
Nlferu
Sep 19, 2023
Replies: 1 comment 2 replies
-
Hello @Seh-Pankaj Your struct is taking 2 elements, favNum and name, so you need to push 2 elements. You can do that only within function. You can do it like below: struct People {
uint256 favoriteNumber;
string name;
}
People[] public people;
function add() public {
People memory firPer = People({favoriteNumber: 707, name: "Pankaj"});
people.push(firPer);
} |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
Seh-Pankaj
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello @Seh-Pankaj
Your struct is taking 2 elements, favNum and name, so you need to push 2 elements. You can do that only within function.
You can do it like below: