【发布时间】:2022-01-11 14:50:43
【问题描述】:
我有一个如下所示的对象数组:
const arr = [
{ type: 'type', fields: ['field1'] },
{ type: 'type2' },
{ type: 'type', fields: ['field2'] },
]
并且我需要找到具有相同类型的对象来合并其中的字段键,如下所示:
const arr = [
{ type: 'type', fields: ['field1', 'field2'] },
{ type: 'type2' },
{ type: 'type', fields: ['field1', 'field2'] },
]
我的计划是通过数组进行过滤,但我的问题是我不知道哪种类型会向我发送 API,因此按 item.type 过滤对我不起作用。
【问题讨论】:
-
欢迎来到 Stack Overflow!访问help center,使用tour 了解内容和How to Ask。请首先>>>Search for related topics on SO,如果您遇到困难,请发布您的尝试的minimal reproducible example,并使用
[<>]记录输入和预期输出sn-p 编辑器。
标签: javascript arrays object