How to increase array size in upgradeable contract?

I have a UUPS Upgradeable contract where I set the initial length of an array variable in the initialize function:

contract MyContract is OwnableUpgradeable, UUPSUpgradeable {
  address[] internal _owners;

  function initialize() public initializer {
    _owners = new address[](100);

  // other logic...

However this array is full now and I need to increase it, is there a way to do it now?


the only way to increase the size of an array (for solidity >=6.0.0) is by using the push() function, see here:

so you could deploy a new implementation that calls push(newOwner) whenever you need to add a new owner. Make sure the array is full when you do that though, else there might be trouble when you need to iterate through that array and you have indices without value

Thanks, is there any harm in doing something like:

function increaseOwners() external onlyOwner {
  address[] memory _newOwners = new address[](200);

  for (uint256 i = 0; i < _owners.length; i++) {
    _newOwners[i] = _owners[i];

  _owners = _newOwners;

The main reason to increase the length in one go is that there's other logic where I need to add owners in non-sequential order so push won't necessarily work in my case.

looks like it would work, not sure if there are any pitfalls