Hi @david.maluenda,
The Person struct instances are stored sequentially in an array (people
). A value stored in any array is referenced with its index number. This is different to a mapping, where each value is mapped to a key, which, instead of a number, could be an address, for example.
The _index
argument passed to getPerson() is the array index number of the Person instance you want to reference. In the following line of code, this Person instance is first stored temporarily in a local variable personToReturn
.
Person memory personToReturn = people[_index];
Then, in the return statement, individual property values of this Person instance (name and age) are referenced and returned. This could also be done without the local variable, as follows:
function getPerson(uint _index) public view returns(uint, string memory) {
return(people[_index].age, people[_index].name);
}
Just let me know if anything is still unclear, or if you have any further questions