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: 
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);

```
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);

```