# Duplicating a 2d array into a new one

**URL:** <https://forum.kirupa.com/t/duplicating-a-2d-array-into-a-new-one/229617>\
**Category:** Uncategorized\
**Created:** [June 19, 2007, 1:19am UTC](https://forum.kirupa.com/t/duplicating-a-2d-array-into-a-new-one/229617 "2007-06-19T01:19:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregmax17](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/gregmax17/32/2243_2.png) [@gregmax17](https://forum.kirupa.com/u/gregmax17)\
**Post date:** [June 19, 2007, 1:19am UTC](https://forum.kirupa.com/t/duplicating-a-2d-array-into-a-new-one/229617/1 "2007-06-19T01:19:00Z")

</div>

but in a more complex way. I have an existing 2d array that I want to copy to a new 2d array (but the NEW array can vary in size!).

For example, my current 2d array with the data:

var old\_array =  
[[0,1,2,3,4],  
[5,6,7,8,9],  
[10,11,12,13]];

And I want the new array to contain the same data as the old\_array, yet if the new array is larger, it will put a zero instead of ‘undefined’…like this:

var new\_array =  
[[0,1,2,3,4,0,0],  
[5,6,7,8,9,0,0],  
[10,11,12,13,0,0],  
[0,0,0,0,0,0,0]];

Am I making sense? Thanks in advance 🙂
