How to initialize an array inside the function and push items into it? I'm not gonna initialize outside the function.
Here's my code:
function tokenOfOwner(address owner) public virtual returns (uint256[] memory)
{
uint256[] storage _ownerAmount;
uint256 amount = ERC721.balanceOf(owner);
for(uint256 i = 0; i< amount ; i++)
{
_ownerAmount.push(_ownedTokens[owner][i]);
}
return _ownerAmount;
}
The error message shows:
TypeError: This variable is of storage pointer type and can be accessed without prior assignment, which would lead to undefined behaviour.