Question: I am just learning javascript.I am pretty confused with manipulating multidimensional arrays.

```
var myarr = [ 
       [ 7, 9, 10 ], 
       [ 6, 9 ], 
       [ 5, 9 ] 
  ]

```

I want to insert zero like this.What is the smart way to do this in javascript

```
       [ 
           [ 7, 9, 10 ], 
           [ 6, 9, 0 ], 
           [ 5, 9, 0 ] 
       ]

```

Answer: 
You could get first the max length of the inner arrays and push zeroes until all inner arrays have the same length.

```js
var myarr = [[7, 9, 10], [6, 9], [5, 9]],
    length = myarr.reduce(function (r, a) { return Math.max(r, a.length); }, 0);

myarr.forEach(function (a) {
    while (a.length < length) {
        a.push(0);
    };
});

console.log(myarr);
```

```css
.as-console-wrapper { max-height: 100% !important; top: 0; }
```
If your array is a numbers only arbitrarily nested filled array, you could use a recursive function like I have here:

```
function fillArray(array,  val){

  for(var i=0; i<array.length; i++){    
    if(typeof(array[i]) === 'number'){
        array[i] = val;
    }else{
        fillArray(array[i],  val);
    }
  } 

}
var test = [5,[3,8,-1,[3,4,5,2,1],[2] ],[[2,2],[3]],[[2,3],[4]],[[2,4],[5]]];
fillArray(test, 0);

```