Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 mins ago.
Improve this questionlet data = [{
year: '',
data_yearly: [{
month: '',
data_monthly: []
},
// ...
]
},
// ...
];
let new_item = {
year: '',
month: '',
// ...
};
When new_item
want to add to data array first I want check the year
of new item with data. If exist (call this index: A
) then check the month of object with data[A].data_yearly
items. If exist (call it x
), add new_item
to data[A].data_yearly[x].da开发者_如何学Cta_monthly
.
If not exist add month of new_item
to data[A].data_yearly
and then add new_item
to data[A].data_yearly[new index]
.
In other case if year of new_item
doesn't exist in data, add year of new_item
to data and then add month of new_item
to data_yearly
, then...
What is the best way?
精彩评论