# Solidity - push elements to different arrays per array name **Published by:** [N00b21337](https://paragraph.com/@n00b21337/) **Published on:** 2023-01-11 **URL:** https://paragraph.com/@n00b21337/solidity-push-elements-to-different-arrays-per-array-name ## Content 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); } ## Publication Information - [N00b21337](https://paragraph.com/@n00b21337/): Publication homepage - [All Posts](https://paragraph.com/@n00b21337/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@n00b21337): Subscribe to updates - [Twitter](https://twitter.com/0xCardinalError): Follow on Twitter