What is the exact syntax to push data using the above given syntax?


I would do as follow:

mapping(address=>address[]) addressToMany;
function addAddress(address _address) public {
  • 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. – Rudrika Apr 30 '19 at 13:02
  • @Rudrika You're welcome :). To delete the data you can use the delete statement as follow: delete array[index]; – strangethingspy Apr 30 '19 at 13:09
  • I am working with double mapping and address => address[] mapping. – Rudrika Apr 30 '19 at 13:22
  • 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 particular subAddress which has 0 balance. – Rudrika Apr 30 '19 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] – strangethingspy Apr 30 '19 at 13:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.