Lesson 2: Array are not clear #2597
-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
@Salutix Hey! These both are different things but because the symbol is the same that is why it is confusing you. Let me clear it up! uint256 arrayName[3]; Here this nameToFavoriteNumber[_name] = _favoriteNumber; But here So here what we are doing is that every time we call the |
Beta Was this translation helpful? Give feedback.
@Salutix Hey! These both are different things but because the symbol is the same that is why it is confusing you. Let me clear it up!
Here this
[ ]
symbol we use to create a fixed-size array. It indicates the length of the items it can contain.nameToFavoriteNumber[_name] = _favoriteNumber;
But here
[ ]
this symbol has a different meaning,nameToFavoriteNumber
is amapping
. The mapping you can think of it as a key/value pair (key => value). And it does not link 1 key with multiple values, it only links 1 key with 1 value.So here what we are doing is that every time we call the
addPerson
function and passname
andfavoriteNumber
, It will do two 2 things, 1. It will c…