Question: I have the need to get things by id. What I decided is to initialize things by using a vector/array. So I only use:

```
array[id];

```

And I'm getting them by id! One problem though is setting the values. Say I'm inserting an object with id of 1000 *first*:

```
array[1000] = myobj;

```

Obviously this returns an error.

What is a good way to remedy this? Another datastructure? Or should I initialize the array elements to null (and what is the best way to do that, barring loops?)

I know how many elements there are to insert.

Answer: 
If you know the "max" id value ahead of time, you can just allocate the array to "max"+1 but it could waste a lot of space if your ids are sparse. The alternative is to use a map data structure.

I don't know much about actionscript but it looks like it has a map collection:
<http://www.adobe.com/devnet/actionscript/learning/as3-fundamentals/associative-arrays.html>
`Array` in AS3 is a composition of two classic data structures `Array` and `HashMap`. `Array` is using when you write objects by integer keys in order, `HashMap` is using when you write objects by String key or integer key with gaps (for example `array[0]=1, array[2]=2`, here `1` will be placed to `Array` and `2` will be placed to the `HashMap`). Your case is number 2.

You can use `Object` class, it's the AS3 `HashMap` implementation with String key or `Dictionary` with keys of type `Object`.

I use in my projects own data structure `ItemSet` - the composition of `Array` (for counting collection size and object indexes) and `Object` (for storing objects by their id).