【发布时间】:2021-08-06 18:51:18
【问题描述】:
我正在尝试从一个数组对象中删除重复项,该数组对象是另一个数组中的属性。
我不想删除所有重复项,但只保留一个唯一的。
我有这个数组:
const arr = [
{
foo: "test",
bar: [
{
address: "Duplicated",
port: 100001,
},
],
},
{
foo: "Test2",
bar: [
{
address: "Duplicated",
port: 100000,
} /*Remove this duplicate in every property bar but only by the property `address` */,
{
address: "Not duplicated",
port: 100000,
}
],
},
];
输出会是这样的:
[
{
foo: "test",
bar: [
{
address: "Duplicated",
port: 100001,
},
],
},
{
foo: "Test2",
bar: [
{
address: "Not duplicated",
port: 100000,
},
],
},
];
我尝试了几件事,但都没有成功,我对此感到非常困惑。
【问题讨论】:
-
请包含您尝试过的代码。您将获得有关您实际缺少的内容的反馈,而不仅仅是适用于这种情况的代码。
标签: javascript arrays typescript