0

Is there a way for me to get the total number of elements in a mapping in Solidity?

  • Not unless you count it by yourself (increment after the creation of a new entry, decrement after the deletion of an existing entry). – sea212 Apr 5 at 22:43
1

You can't. There is no way to know how many entries there are in a mapping.

If you need to keep tract of the mapping's elements you can use a separate array which holds extra information about the mapping elements

| improve this answer | |

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.