开发者

best way to update this array [closed]

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜