I have an array called "pedidos" which the length is x because it depends on the amount of "orders" we get this get's updated automatically through firebase.
each "order" has the following attributes:
acudiente: ""
banco: "Global Bank"
data: (12) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
email: ""
escuela: "Academia Internacional David"
estadoDeDisponibilidad: "Pendiente"
estadoDePago: "Pendiente"
fecha: "11/22/2021"
grado: "1° Grado"
id: "[AID]PM-345"
identificacion: ""
metodoDePago: "ACH"
nombre: "Brihana Orisiveth De Gracia Concepción "
phone: ""
total: "346.45"
totalPagado: 0
uid: "13eLyFqGGrZ0vTu3llpVxeFCBun2"
Now, each order has an attribute called "data" which is x because people can order x amount of stuff so 12 is not a constant. Each item inside data has the following attributes:
descripcion: "ACCELIUM - Programa de Tecnología"
disponible: 0
editorial: "Programa"
grado: (6) ['1° Grado', '2° Grado', '3° Grado', '4° Grado', '5° Grado', '6° Grado']
id: "L-25304"
materia: "Tecnologia"
ordenados: 12
precio: "35.00"
tipo: "Programa"
Now I'm trying to make a NEW Array that will contain every data array, which means that if there are 5 orders with 5 items each it should be an array of 25, this is a very simple for loop:
for(let x = 0; x < pedidos.length; x++){
for(let y = 0; y < pedidos[x].data.length; y++){
pedidosExcel.push(pedidos[x].data[y])
}
}
however I also want some attributes from the main array and not just the attributes from the array called "data", so I wanted to know if it was possible to MERGE attributes from each other.
Update
So I wasn't able to do what I wanted but I manage to get close to it with the following piece of code, however if I do this it ends up as an array inside an array for some reason. I manually set up every attribute because I wanted to overwrite some of them since some attributes have the same name
for(let x = 0; x < pedidos.length; x++){
for(let y = 0; y < pedidos[x].data.length; y++){
pedidosExcel.push(pedidos[x].data[y])
pedidosExcel[y] = [{
id: pedidos[x].id,
nombre: pedidos[x].nombre,
escuela: pedidos[x].escuela,
grado: pedidos[x].grado,
fecha: pedidos[x].fecha,
descripcion: pedidos[x].data[y].descripcion,
tipo: pedidos[x].data[y].tipo,
editorial: pedidos[x].data[y].editorial,
precio: pedidos[x].data[y].precio,
}]
}
}
Hope this is more clear than my previous explanation.