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; }
```
```
var maxLength=0;
for(var i=0;i<myarr.length;i++){
   if(myarr[i].length>maxLength){
      maxLength=myarr[i].length
  }
}
for(var i=0;i<myarr.length;i++){
    if(myarr[i].length!=maxLength){
    fillZeros(myarr[i])
    }
  }
function fillZeros(child){
    while(child.length!=maxLength)
     {child.push(0);}
}

```