I want to be able to edit values in a struct. My struct is declared and mapped like this :

struct entityLinks{
        string linksUrl;
        string linksName;
    mapping (uint => entityLinks) allLinks;

The only matter is that i don't know how to dynamicly select the proper value in my struct. The only way I found was to pass a _targeted argument to manually select the proper property.

   function editEntityLink(uint _entityLinks,uint _targeted,string _content) external onlyOwner() {
            if(_targeted == 1){
                allLinks[_entityLinks].linksName = _content;
            else if(_targeted == 2){
                allLinks[_entityLinks].linksUrl = _content;

I want to be able to have something which fit in 1 line without endless if ... (Trying to use a string as argument to edit the property don't work)

Thanks , I hope I was clear !

  • I don't understand your problem. First targeted and entityLinks are the exact same values, so why do you use both? Moreover, a mapping is a key-pair value, and you use it properly. So what is your problem exactly? Do you want to check if the mapping is empty at theis specific key? Commented Oct 5, 2018 at 22:44
  • I am struggling to dynamically target a value for a mapping ! I would be able to edit allLinks[_entityLinks]._dynamicProperty (_dynamicProperty would be an argument) Commented Oct 6, 2018 at 0:28

1 Answer 1


I've done quite a bit of work for this problem and I found nothing that would work. I would suggest the ternary operator, but it fell short for me. The if-else construct might be the way to go friend.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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