Weedpacket's method is how I usually deal with this situation. Basically, you're defining the next index - ".length" tells you how many items are in the array (e.g. 2 if we take JPnyc's code from above). Since arrays start at index #0, the last valid index of the array is length - 1 (or 1, as in JPnyc's example array). So, if you simply take length instead of subtracting one, you'd get the next unused ID.