My JavaScript code includes an array
and a list
.
const headr = [H1, H2 ,H3, H4]
const Year = ['1Y', '2Y' ,'3Y', '4Y']
let arr_ = {
H1 : Array(3)
0 : {Year: '1Y', Type: 'TypeA', Value: -41445643364}
1 : {Year: '2Y', Type: 'TypeA', Value: -11928080380}
2 : {Year: '3Y', Type: 'TypeA', Value: 32370503415}
H4 : Array(4)
0 : {Year: '1Y', Type: 'TypeA', Value: -41445643364}
1 : {Year: '2Y', Type: 'TypeB', Value: -11928080380}
2 : {Year: '3Y', Type: 'TypeA', Value: 32370503415}
3 : {Year: '4Y', Type: 'TypeA', Value: 32370503415}
}
I would like to transform this data into a new array
structured as shown below:
H1 : Array(3)
0 : {Year: '1Y', Type: 'TypeA', Value: -41445643364}
1 : {Year: '2Y', Type: 'TypeA', Value: -11928080380}
2 : {Year: '3Y', Type: 'TypeA', Value: 32370503415}
3 : {Year: '4Y', Type: '-', Value: 0}
H2 : Array(4)
0 : {Year: '1Y', Type: '-', Value: 0}
1 : {Year: '2Y', Type: '-', Value: 0}
2 : {Year: '3Y', Type: '-', Value: 0}
3 : {Year: '4Y', Type: '-', Value: 0}
H3 : Array(4)
0 : {Year: '1Y', Type: '-', Value: 0}
1 : {Year: '2Y', Type: '-', Value: 0}
2 : {Year: '3Y', Type: '-', Value: 0}
3 : {Year: '4Y', Type: '-', Value: 0}
H4 : Array(4)
0 : {Year: '1Y', Type: 'TypeA', Value: -41445643364}
1 : {Year: '2Y', Type: 'TypeB', Value: -11928080380}
2 : {Year: '3Y', Type: 'TypeA', Value: 32370503415}
3 : {Year: '4Y', Type: 'TypeA', Value: 32370503415}
}
How can I achieve this desired array format? One approach I am considering is creating a new dictionary or array structured like the following example and using a for loop
for pushing values:
let dict_ = {
'H1' : [], 'H2' : [], 'H3' : [], 'H4' : []
}