# Dynamically Creating a 3 Dimensional Array?

**URL:** <https://forum.kirupa.com/t/dynamically-creating-a-3-dimensional-array/65175>\
**Category:** flash\
**Created:** [September 23, 2004, 5:47pm UTC](https://forum.kirupa.com/t/dynamically-creating-a-3-dimensional-array/65175 "2004-09-23T17:47:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![smallgreY](https://avatars.discourse-cdn.com/v4/letter/s/94ad74/32.png) [@smallgreY](https://forum.kirupa.com/u/smallgreY)\
**Post date:** [September 23, 2004, 5:47pm UTC](https://forum.kirupa.com/t/dynamically-creating-a-3-dimensional-array/65175/1 "2004-09-23T17:47:46Z")

</div>

:puzzled: This seemingly trivial problem is _really_ confounding me. I have a 3 dimensional array like this …

```auto

[font=Courier New]oldmap = [[['a1',0],['a1',1]], [/font]
[font=Courier New] [['a0',1],['a1',0]]];[/font]

```

I simply want to take this array, modify the data, and create a new array. Here’s the code (minus the transform functions):

```auto

 
[font=Courier New]newmap = new Array();[/font]
 
[font=Courier New]for (i=0;i<map_height;i++) { [/font]
[font=Courier New]for (j=0;j<map_width;j++) {[/font]
 
[font=Courier New]	old_label = oldmap*[j][0];[/font]
[font=Courier New]	old_type = oldmap*[j][1];[/font]
 
[font=Courier New]	// transform the data[/font]
[font=Courier New]	new_label = transformLabel(old_label);[/font]
[font=Courier New]	new_type = transformType(old_type);[/font]
 
[font=Courier New]	state = [new_label,new_type];[/font]
 
[font=Courier New]	// THIS LINE IS NOT WORKING[/font]
[font=Courier New]	newmap*[j].push(state);[/font]
 
[font=Courier New]} // end j [/font]
[font=Courier New]} // end i[/font]
 
[font=Courier New]trace(newmap);[/font]
 

```

When I trace “newmap” I always get undefined.

Thanks in advance … been reading the forum for a week now … great info … good to meet you! 🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 24, 2004, 8:06am UTC](https://forum.kirupa.com/t/dynamically-creating-a-3-dimensional-array/65175/2 "2004-09-24T08:06:02Z")

</div>

maybe you’ve to make first the arrays then push something…

this is not tested and maybe you’ve to add it a little different but i hope it works…

newmap = new Array();

for (i=0;i\<map\_height;i++) {  
var new\_array = new Array();  
newmap.push(new\_array);  
for (j=0;j\<map\_width;j++) {  
var new\_array2 = new Array();  
newmap\*.push(new\_array2);  
old\_label = oldmap\*[j][0];  
old\_type = oldmap\*[j][1];

```
    // transform the data
    new_label = transformLabel(old_label);
    new_type = transformType(old_type);

    state = [new_label,new_type];

    // THIS LINE IS NOT WORKING
    newmap*[j].push(state);

```

} // end j  
} // end i

trace(newmap);

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 24, 2004, 8:32am UTC](https://forum.kirupa.com/t/dynamically-creating-a-3-dimensional-array/65175/3 "2004-09-24T08:32:25Z")

</div>

Exactly. In order to use the push () method, you have to tell Flash that newmap’s elements are arrays as well. Pieter’s code is probably correct, but I think that this is enough:

```auto
 
[font=Courier New]newmap = new Array();[/font]
 
[font=Courier New]for (i=0;i<map_height;i++) { [/font]
**newmap* = [] ;**
  [font=Courier New]for (j=0;j<map_width;j++) {[/font]
 
[font=Courier New]	var old_label = oldmap*[j][0];[/font]
[font=Courier New]	var old_type = oldmap*[j][1];[/font]
 
[font=Courier New]	// transform the data[/font]
[font=Courier New]	var new_label = transformLabel(old_label);[/font]
[font=Courier New]	var new_type = transformType(old_type);[/font]
 
[font=Courier New]	var state = [new_label,new_type];[/font]
 
[font=Courier New]	// THIS LINE IS NOT WORKING[/font]
[font=Courier New]	newmap*[j].push(state);[/font]
 
  [font=Courier New]} // end j [/font]
[font=Courier New]} // end i[/font]
 
[font=Courier New]trace(newmap);[/font]

```
