I have two arrays that I need to combine. Most array combining tips I can find concat. But I do not want to add to the end of the array, I need to add a key / value pair from array1to each object in array2.
I need to combine this array1:
[
"Basket Abandonment",
"Downloads",
"App Version"
]
With this array2:
[
{
bottom: {
comp : "",
details, : "3.1.39 22nd Jul 2015",
status : "",
title : "Previous Version",
value : "8.7%"
},
top: {
details: "3.1.40 25th August 2015",
status: "",
comp: "",
title: "Latest Version",
value: "86%",
}
},
{
bottom: {
value: "469",
title: "Total Reviews",
status: "neutral",
comp: "same",
details: "2 New This Week"
},
top: {
details: "Version 3.1.40",
status: "neutral",
comp: "same",
title: "Average Rating",
value: "4.0"
}
},
{
bottom: {
value: "469",
title: "Total Reviews",
status: "neutral",
comp: "same",
details: "2 New This Week"
},
top: {
details: "Version 3.1.40",
status: "neutral",
comp: "same",
title: "Average Rating",
value: "4.0"
}
}
]
In a new merged array, I need to add a key titleto each object with a value from the first array, so the resulting array looks like this:
[
{
title: "Basket Abandonment",
bottom: {
comp : "",
details, : "3.1.39 22nd Jul 2015",
status : "",
title : "Previous Version",
value : "8.7%"
},
top: {
details: "3.1.40 25th August 2015",
status: "",
comp: "",
title: "Latest Version",
value: "86%",
}
},
{
title: "Downloads",
bottom: {
value: "469",
title: "Total Reviews",
status: "neutral",
comp: "same",
details: "2 New This Week"
},
top: {
details: "Version 3.1.40",
status: "neutral",
comp: "same",
title: "Average Rating",
value: "4.0"
}
},
{
title: "App Version",
bottom: {
value: "469",
title: "Total Reviews",
status: "neutral",
comp: "same",
details: "2 New This Week"
},
top: {
details: "Version 3.1.40",
status: "neutral",
comp: "same",
title: "Average Rating",
value: "4.0"
}
}
]