Can we just replace the last element of a mask group to make a new mask?

Or do we have to ungroup, re-select the other elements and then use createMaskGroup to re-create the group?

Unfortunately, if the action is not possible on the XD app itself, it cannot be programmatically done using plugins.