【发布时间】:2021-04-03 05:31:25
【问题描述】:
我有一个从 JSON 响应生成的对象数组。
所述数组的内容结构如下:
const array = [
{title: "user generated title", message: "random user generated text", status: "Active/Inactive"},
{200 + more objects with the exact same key/values as the first},
...,
...
]
我想用完全相同的对象减去特定的键/值对创建一个新数组。
即,制作完全相同的数组而不说出所有消息:“用户消息”键/值对。 (不过,我想从数组中的对象中删除多个键/值对。)
应该是这样的
const array = [
{title: "user generated title", status: "Active/Inactive"},
{200 + objects just like the first without the message: "message text"},
...,
...
]
【问题讨论】:
-
对象数组与另一个数组没有区别,使用 for 或 foreach 循环对其进行迭代,然后您可以使用 Object.entries() (developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…) 遍历对象键和值。当然,只将具有您需要的键和值的对象添加到新数组中。
-
这能回答你的问题吗? Remove property for all objects in array
标签: javascript arrays sorting filter javascript-objects