# Vector contents on declaration

**URL:** <https://forum.kirupa.com/t/vector-contents-on-declaration/319028>\
**Category:** flash\
**Created:** [February 7, 2011, 7:41am UTC](https://forum.kirupa.com/t/vector-contents-on-declaration/319028 "2011-02-07T07:41:43Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![carrot](https://avatars.discourse-cdn.com/v4/letter/c/9de0a6/32.png) [@carrot](https://forum.kirupa.com/u/carrot)\
**Post date:** [February 7, 2011, 7:41am UTC](https://forum.kirupa.com/t/vector-contents-on-declaration/319028/1 "2011-02-07T07:41:43Z")

</div>

Is it possible to add elements to a vector when it is declared, like you can for arrays?

e.g. for an array, you can just go

```auto
var myArray:Array = [2, 4, 1, 17, 16, 24]

```

which will leave you with an myArray filled with those numbers in one nice, tidy single line of code :).

However vectors seem to complain whenever you try to add anything to them when you instantiate them. As far as I know you have to do this instead

```auto
var myVector:Vector.<int> = new Vector.<int>
myVector.push(2)
myVector.push(4)
myVector.push(1)
myVector.push(17)
myVector.push(16)
myVector.push(24)

```

which of course is much more annoying.

(While typing this I realised you could just put all the pushes onto one line with _myVector.push(2,4,1,17,16,24)_ making it much nicer, but the question still stands)
