I have a struct array like so:
struct People {
uint256 age;
string name;
}
People[] public peopleArray;
Is there a way I can easily get an array containing the ages of the People? The code I have now is something like:
function getPeopleAges() public view returns (uint256[] memory) {
uint256[] memory temp = new uint256[](peopleArray.length);
for (uint8 i = 0; i < peopleArray.length; i++) {
temp[i] = peopleArray[i].age;
}
return temp;
}
This seems needlessly bulky, so I was wondering if there was a more simplified or better way to do this. For example, in javascript you can do something like this:
return peopleArray.map(a => a.age);
Is there a solidity equivalent to that?