In my current project, I am attempting to manipulate JavaScript object arrays using lodash. The goal is to stack array values from different objects and map them to corresponding objects in a new array. Here's an example of what I'm working with:
olympicmedals = {
'2008': [{'country': 'China', 'golds': 51}, {'country': 'USA', 'golds': 36}],
'2012': [{'country': 'China', 'golds': 38}, {'country': 'USA', 'golds': 46}]
}
The desired outcome is as follows:
olympicmedals = [
{'country': 'China', 'golds2008': 51, 'golds2012': 38},
{'country': 'USA', 'golds2008': 36, 'golds2012': 46}
]
I am looking to achieve this for the purpose of creating charts in amCharts, which can be seen here (click 'View Demo Source' therein).
My understanding is that the _.map() function may be useful for this task, but I am not entirely sure how to proceed. Any guidance would be greatly appreciated. Thank you!