You could do:
thiso.hatzlist = { 0, 1, 2, 3}; -> as standard hats
Then when you buy a hat, like: hat number 50.. you make the buy script do: client.hat_50 += 1; so for example client.hat_50 is 2 when you bought 2 times hat 50.
After that, to add the hat to the array you do:
for ( i: getstringkeys( "client.hat_"))
thiso.hatzlist.add( client.( "hat_" @ i));
Then thiso.hatzlist would be 0,1,2,3,50
To read a part of the array, do: thiso.hatzlist[ index], the index of an array starts with 0, so thiso.hatzlist[ 4] would say: 50 in this case..
