# Solidity - push elements to different arrays per array name

By [N00b21337](https://paragraph.com/@n00b21337) · 2023-01-11

---

I wanted to have one setter for array so I can just pass the variable to it and push the element to proper array, way to do this would be to have one internal function and one public that gets the element and chooses proper array.

     string[] public goalkeeepr = []
     string[] public left_back = []
    
    
    .......
     function addPlayer(string memory position, string memory name) public {
            if (keccak256(bytes(position)) == keccak256(bytes("GK"))) {
                addToArray(goalkeeepr, name);
            }
            else  if (keccak256(bytes(position)) == keccak256(bytes("LB"))) {
                addToArray(left_back, name);
            }
        }
    
       function addToArray(string[] storage ar, string memory x) internal {
                ar.push(x);
        }

---

*Originally published on [N00b21337](https://paragraph.com/@n00b21337/solidity-push-elements-to-different-arrays-per-array-name)*
