I have json that looks like this (copied from dev tools inspector)
salePurchases
salesPeriods: Array[2]
0: Object
data: Array[5]
0: Object
1: Object
2: Object
3: Object
4: Object
period: "2011"
1: Object
data: Array[5]
0: Object
1: Object
2: Object
3: Object
4: Object
period: "2012"
purchasePeriods: Array[2]
0: Object
data: Array[5]
0: Object
1: Object
2: Object
3: Object
4: Object
period: "2011"
2: Object
data: Array[5]
0: Object
1: Object
2: Object
3: Object
4: Object
period: "2012"
I want to pull it apart and make it creat a new object that looks like this -
OrderedByYears:
2011:
data: Array[10]
0: Object // this should be the 1st item from the salesPeriods array with a period of 2011
1: Object // this should be the 1st item from the purchasePeriods array with a period of 2011
2: Object
3: Object
4: Object
5: Object
6: Object
7: Object
8: Object
9: Object // this should be the 5th item from the salesPeriods array with a period of 2011
10: Object // this should be the 5th item from the purchasePeriods array with a period of 2011
2012:
data: Array[10]
0: Object // this should be the 1st item from the salesPeriods array with a period of 2012
1: Object // this should be the 1st item from the purchasePeriods array with a period of 2012
2: Object
3: Object
4: Object
5: Object
6: Object
7: Object
8: Object
9: Object // this should be the 5th item from the salesPeriods array with a period of 2012
10: Object // this should be the 5th item from the purchasePeriods array with a period of 2012
I'm basing the arrangement by the key 'period' and then alternating between joining each array together but alternating between the relavant object salesPeriods and purchasePeriods.
I'm sure this is relatively simple using underscore. Anyone know if it's an easy thing to do? Explaining the steps involved would be much appreciated.