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: 
Here is a solution.

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

var rows = myarr.length;
var cols = 0;

for (var i in myarr) {
  if (myarr[i].length > cols)
    cols = myarr[i].length;
}

for (i = 0; i < rows; i++) {
  for (j = 0; j < cols; j++) {
    if (myarr[i][j] == undefined)
      myarr[i][j] = 0;
  }
}

console.log(myarr);
```
using map function

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

       var arr1 = arr.map(function(e){
       var arr2 = [];
        if(e.length < 3)
            e.push(0);

         arr2.push(e);
         return arr2;

       });

      alert(arr1);

```