开发者

best way to update this array [closed]

开发者 https://www.devze.com 2022-12-07 17:19 出处:网络
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post.
Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 9 mins ago.

Improve this question
let 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?

0

精彩评论

暂无评论...
验证码 换一张
取 消