I have two arrays, which are:
data [
0{
nome: a
numero: 2
}
1{
nome: b
numero: 3
}
2{
nome: b
numero: 3
}
3{
nome: b
numero: 8
}
]
dataNota[
0{
nf: 9999
numero: 2
}
1{
nf: 2000
numero: 3
}
2{
nf: 1000
numero: 5
}
]
I need to generate a new array containing the information where my id would be the "number" field in both the data and date arrays.
I'm doing the following for:
for(var x=0; x<data.length; x++){
for (var y=0; y<dataNota.length; y++){
if(data[x].numero == dataNota[y].numero){
conf[x][0] = data[x].numero;
conf[x][1] = dataNota[y].nf;
}else{
conf[x][0]="";
}
}
}
var excel = nodeExcel.execute(conf);
res.setHeader('Content-Type', 'application/vnd.openxmlformats');
res.setHeader("Content-Disposition", "attachment; filename=" + "Teste.xlsx");
res.end(excel, 'binary');
However, whenever you find an equal number in both arrays, it fills only one of the values, never all, and the name fills in for all.
I would like to do it another way, maybe using a each, because my problem is in the for. Any suggestions?