Skip to content

Lesson 2 - Array vs Mapping #1654

Answered by mattaereal
ghost asked this question in Q&A
Aug 9, 2022 · 2 comments · 2 replies
Discussion options

You must be logged in to vote

Without explicitly talking about lesson 2, since an array and a mapping are different structure types, unless your mapping uses a uint256 as an index mapped to the same type of the array, then you are not specifically doubling all the data. So in practice, it depends on the use case of the contract.

If by having two different data structures, you increase the storage cost, but save gas by querying them in a criteria which exploits those data structures, then great.

Talking explicitly about Lesson 2, I'm guessing you're talking about these two declarations:

    People[] public people;
    mapping(string => uint256) public nameToFavoriteNumber;

In the case you need to see what's my favorit…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@ghost
Comment options

Answer selected by alymurtazamemon
Comment options

You must be logged in to vote
1 reply
@ghost
Comment options

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