Skip to content

Push function error in REMIX #6138

Answered by Nlferu
Seh-Pankaj asked this question in Q&A
Sep 19, 2023 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

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);
    }

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Seh-Pankaj
Comment options

@Nlferu
Comment options

Answer selected by Seh-Pankaj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants