Q:

How to compare (and add if don't exists) elements from 2 arrays at Google App Script? 

everyone I'm trying to get the best way to compare two arrays and add a new element with value 0 if there's any difference between them.  First I got this 2 arrays:
  var niv = ["FB","Bach","FPSE","FPPE","AA"];
  var values = [["H", "FB", 3286.25, 509.75],["H", "Bach", 4587.5, 522.5],
    ["H", "FPPE", 160, 2624],["H", "AA", 334, 7454],
    ["M", "FB", 3803.75, 1743.25],["M", "Bach", 7856.5, 709.5],
    ["M", "FPPE", 799, 3785],["M", "AA", 1055, 11718,2],["N", "FB", 45, 0.0, 0.0]];

This is a poor example of what Im trying to do:
  for (var i = 0; i < data.length; i++) {
    for (var j = 0; j < values.length; j++) {
      if (data[i][0] == values[j][0] && 
        (values[i][1] == "FB" || values[i][1] == "Bach" || 
         values[i][1] == "FPSE" || values[i][1] == "FPPE" || values[i][1] == "AA")) {
        data[i].push(values[j][2],values[j][3])
      } else {
       data[i].push(0,0)
    }
  }

}
All I want to get is this:
[["H", "FB", 3286.25, 509.75],["H", "Bach", 4587.5, 522.5],
 ["H", "FPSE", 0.0, 0.0],["H", "FPPE", 160, 2624],
 ["H", "AA", 334, 7454],["M", "FB", 3803.75, 1743.25],["M", "Bach", 7856.5, 709.5],
 ["M", "FPSE", 0.0, 0.0],["M", "FPPE", 799, 3785],
 ["M", "AA", 1055, 11718,2],["N", "FB", 45, 0.0],["N", "Bach", 0.0, 0.0],
 ["N", "FPSE", 0.0, 0.0],["N", "FPPE", 0.0, 0.0],["N", "AA", 0.0, 0.0]];

A:

I hope I'm not late. 
I think you should divide the work into several sections so that it is not so difficult to reach the goal. 
Starting from the two arrays with the information: niv and values
 var niv = ["FB","Bach","FPSE","FPPE","AA"];
 var values = [["H", "FB", 3286.25, 509.75],["H", "Bach", 4587.5, 522.5],
    ["H", "FPPE", 160, 2624],["H", "AA", 334, 7454],
    ["M", "FB", 3803.75, 1743.25],["M", "Bach", 7856.5, 709.5],
    ["M", "FPPE", 799, 3785],["M", "AA", 1055, 11718,2],["N", "FB", 45, 0.0, 0.0]];

I propose to divide the array values into 3 arrays, one for H, another for M and another for N.
 var man = [];
 var wom = [];
 var unk = [];  

 for (var i = 0; i < values.length; i++){
   if (values[i][0] == "H") man.push(values[i]);
   if (values[i][0] == "M") wom.push(values[i]);
   if (values[i][0] == "N") unk.push(values[i]);
 }

Then it is a question of going through the arrays and checking whether or not the values correspond to the array niv.  To verify that, I propose that you make a function that receives an array and a string with the word to search and returns true or false if it finds it or not. 
Knowing if it is or not, you can add a new element in the array.  With the splice method the element will be added in the position where it should be.  With this you would have 3 complete and ordered arrays. 
 for (var i = 0; i < niv.length; i++){  
   if(!checkArray(man,niv[i])){
     man.splice(i,0,["H",niv[i],0,0]);
   }
 }

 for (var i = 0; i < niv.length; i++){
   if(!checkArray(wom,niv[i])){
     wom.splice(i,0,["M",niv[i],0,0]);
   }
 }

 for (var i = 0; i < niv.length; i++){
   if(!checkArray(unk,niv[i])){
     unk.splice(i,0,["N",niv[i],0,0]);
   }
 }

 function checkArray (array, niv){
    for (var i = 0; i < array.length; i++){
        if(array[i][1] === niv){
            return true;
        }
    }
    return false;
 }

I hope I've helped

