javascript - 具有多个索引打字稿的对象到数组
问题描述
我有一个 API 可以返回很多这样的对象
{ id : 1243, string: "things", bool: 1, date: "2021-21-11"}
{ id : 4233, string: "somethingselse", bool: 1, date: "2021-21-11"}
我可以有许多相同ID的数据
{ id : 1243, string: "other", bool: 0, date: "2021-27-10"}
{ id : 4233, string: "somethings else again", bool: 1, date: "2021-21-11"}
所以我做了一个函数来按 id 我的数据分组以获得类似的东西
object = {
1243: [{
0: {
string: "things",
bool: 1,
date: "2021-21-11"
},
1: {
string: "other",
bool: 0,
date: "2021-27-10"
}
}]
object2 = {
4233: [{
0: {
string: "somethings else again",
bool: 1,
date: "2021-21-11"
}
}]
但现在我想要这样的东西
alldata = [{
1243: [{
"2021-21-11": {
string: "things",
bool: 1
},
"2021-27-10": {
string: "other",
bool: 0
}
}],
4233: [{
"2021-21-11": {
string: "somethings else again",
bool: 1,
}
}]
}]
我不知道该怎么做,我试图生成数组,对象,但没什么大不了的
解决方案
推荐阅读
- sql - 将一个表中一个字段的值与另一表中一列的总和进行比较
- r - R编程:dataframe$column[
] = 工作? - windows - 如何使用空目录以及如何在 Windows 上使用?
- javascript - 无法使用 Ajax 将数据从客户端 (JS) 传递到服务器 (Flask)
- javascript - 要显示的 JavaScript在某个日期之后
- sorting - 报告多个值和排序
- pip - 自托管devpi的客户端URL?
- django - 带有数字键的 Django postgres Json 字段
- android - 我正在尝试将 firebase sdk 添加到 android 项目中
- html - 我怎样才能在这个圈子的顶部添加一个选择类型的收音机?