What is the exact syntax to push data using the above given syntax?
1 Answer
I would do as follow:
mapping(address=>address[]) addressToMany;
function addAddress(address _address) public {
addressToMany[msg.sender].push(_address);
}
-
It worked for my contract perfectly. There is another query related to this, is how to delete data/pop data after pushing it to an array.– RudrikaApr 30, 2019 at 13:02
-
@Rudrika You're welcome :). To delete the data you can use the
delete
statement as follow:delete array[index];
Apr 30, 2019 at 13:09 -
-
I am working with double mapping and address => address[] mapping. Where in first mapping I am storing every address who belongs to one common address using double mapping. And now I am storing those addresses in one array using the above-given solution. The problem is here I am not able to identify indexes of array.
myAddressMapping[commonAddress][subAddresses]
and I want to delete that particularsubAddress
which has 0 balance.– RudrikaApr 30, 2019 at 13:30 -
@Rudrika If I understand correctly, you want to delete the address which has 0 as balance. You can do a for loop and search for it as following:
for(uint i = 0; i < addressToMany[msg.sender].length; i++){ // if statement to check if address has balance 0 delete addressToMany[msg.sender][i]
Apr 30, 2019 at 13:46