【发布时间】:2020-04-25 01:54:32
【问题描述】:
我正在尝试遍历每个对象的评级数组,提取每个内部对象的分数并将它们添加到一个新数组中。
例如,post_id 为“5e1223c2383ce049d8b32eb5”的帖子,我需要一个包含 [1, 4] 的关联数组。和 带有 post_id" "5e146b993dde720850c11c0e" 的帖子将包含 [5] 等。
我们将不胜感激!
[
{
"post_id": "5e1223c2383ce049d8b32eb5",
"ratings": [
{
"_id": "5e134aa9d6c3a51930452d49",
"user": "5e0f76c96a55d6352879daab",
"score": 1
},
{
"_id": "5e134c00cab61f408c75d2f2",
"user": "5e0f34adab4d4b369c57fbd4",
"score": 4
}
]
},
{
"post_id": "5e13592c62008b4e3435472f",
"ratings": []
},
{
"post_id": "5e146b993dde720850c11c0e",
"ratings": [
{
"_id": "5e1473583dde720850c11c13",
"user": "5e0f34adab4d4b369c57fbd4",
"score": 5
}
]
}
]
【问题讨论】:
-
您的预期输出是什么?
{"5e1223c2383ce049d8b32eb5" : [1, 4]}?
标签: javascript arrays node.js sorting