I have the following struct and mapping.
struct consumeID{
address consumerGatewayID;
string serviceConsumerID;
}
mapping(address=>consumeID[]) public pendingAccessRequests;
I want to add and delete elements from the mapping.
For adding elements i tried something like this:
pendingAccessRequests[_producerGatewayID].push(consumeID(_consumerGatewayID, _serviceConsumerID));
Can anyone help me with logic to delete elementsfrom that mapping?
Best Answer
You can use
delete pendingAccessRequest[key]
to remove whole elements from the mapping.If you want to remove an element from the array, you can do that by
delete pendingAccessRequest[key][position]
by indicating the position. But you should be aware that this will not resize the array, it will replace the deleted position with zero bytes.