From a request I give an array that has two objects and those objects in one of the elements there is another array which requires that those elements of that array be added in a new array but that the elements have the parent elements
Try as follows: First I add the journey element to each object in the first array
result.forEach(function(item) {
var data = {"journey":null}
Object.assign(item, data)
});
Then I go through the first array and inside them I go through the other array
// the first array is traversed
result.forEach(function(item,index){
//Creo una variable que contendra el index del primer array
var i = index;
//recorro el segundo array
item.journeys.forEach(function(it,index){
//intento que cada elemento del primer array al elemento journey se le agregue los elemento por recorrido del segundo array
result[i].journey = it;
//E irlo agregando al nuevo array
nuevoarray.push(result[i]);
/******************************************/
Aqui es donde no me queda ya que al final si obtengo los 8 elementos pero en el elemento jurney obtengo el ultimo elemento de del segundo ciclo en lugar de que en nuevo array primer elemento dentro de journey tenga el primer elemento del recorrido, el segundo elemento dentro de journey tenga el segundo elemento del segundo ciclo y asi sucesivamente
Alguien me pueda ayuda
*/
});
});