# Pushing to multidimensional array

**URL:** <https://forum.kirupa.com/t/pushing-to-multidimensional-array/114207>\
**Category:** Uncategorized\
**Created:** [June 25, 2004, 9:44pm UTC](https://forum.kirupa.com/t/pushing-to-multidimensional-array/114207 "2004-06-25T21:44:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Boondogger](https://avatars.discourse-cdn.com/v4/letter/b/e274bd/32.png) [@Boondogger](https://forum.kirupa.com/u/Boondogger)\
**Post date:** [June 25, 2004, 9:44pm UTC](https://forum.kirupa.com/t/pushing-to-multidimensional-array/114207/1 "2004-06-25T21:44:36Z")

</div>

Can anyone help me with the correct syntax for pushing variables to arrays within arrays? I have searched many threads but found nothing that exactly answers my query.

I have a class (Brigade) which amongst other variables contains an array (BrigadeUnits) This is the third element… My Brigades are stored in an array called AllBrigades. I now need to fill the BrigadeUnits array with objects of my Units class.

The hierarchy I want to create is as follows:

AllBrigades (array of Brigades)  
Brigade (object)  
BrigadeUnits (array within Brigade object)  
Unit (Object to be stored in BrigadeUnits array)

I hope this makes sense!

I have tried various approaches including the following, assuming that I am addressing the first Brigade in the array:

AllBrigades [0] [2].push (MyUnit);

But when I trace this I just get undefined.

Where am I going wrong?
