How can I add each item in an array for each duplicate?
Transform:
[
{
"uuid":"EE877ABD-932F-4B4C-AB23-B324363B0B60",
"planning":[
{
"uuid":"6D680178-9B05-4744-A004-163D4B3E1E84",
"start":2016-01-01
},
{
"uuid":"37994EE3-F7E5-4199-A160-6D0B04D287D9",
"start":2016-01-02
}
]
},
{
"uuid":"6BF57C74-F111-4901-A1C3-17E3B094C37E",
"planning":[
{
"uuid":"21E386E9-0527-4EC2-81B5-A4F01B780B46",
"start":2016-03-01
},
{
"uuid":"D590A52C-DC9B-448E-A157-504CCA13FB45",
"start":2016-04-02
}
]
}
]
to:
[
{
"uuid":"EE877ABD-932F-4B4C-AB23-B324363B0B60",
"planning":{
"uuid":"6D680178-9B05-4744-A004-163D4B3E1E84",
"start":2016-01-01
}
},
{
"uuid":"EE877ABD-932F-4B4C-AB23-B324363B0B60",
"planning":{
"uuid":"37994EE3-F7E5-4199-A160-6D0B04D287D9",
"start":2016-01-02
}
},
{
"uuid":"6BF57C74-F111-4901-A1C3-17E3B094C37E",
"planning":{
"uuid":"21E386E9-0527-4EC2-81B5-A4F01B780B46",
"start":2016-03-01
}
},
{
"uuid":"6BF57C74-F111-4901-A1C3-17E3B094C37E",
"planning":{
"uuid":"D590A52C-DC9B-448E-A157-504CCA13FB45",
"start":2016-04-02
}
}
]
I have attempted the code below, but the value of planning is always the first item's value. This code removes the current planning item's value.
var i= 0;
angular.forEach(data, function(value, key){
if(value.planning.length>0){
angular.forEach(value.planning, function(planningvalue, planningkey){
$scope.out.push(value);
$scope.out[i].planning=planningvalue;
console.log($scope.out[i]);
i=i+1;
});
}
});
Thank you