Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/471.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 组合嵌套的对象数组_Javascript_Typescript - Fatal编程技术网

Javascript 组合嵌套的对象数组

Javascript 组合嵌套的对象数组,javascript,typescript,Javascript,Typescript,我拥有以下阵列: const myArray=[ { id:1, 选项:{ a:[ {name:“test-a”,值:10}, {name:“test-b”,值:10}, ], b:[ {name:“test-a”,值:10}, {name:“test-b”,值:10}, ], }, }, { id:2, 选项:{ a:[ {name:“test-a”,值:10}, {name:“test-b”,值:10}, ], b:[ {name:“test-a”,值:10}, {name:“test-b”

我拥有以下阵列:

const myArray=[
{
id:1,
选项:{
a:[
{name:“test-a”,值:10},
{name:“test-b”,值:10},
],
b:[
{name:“test-a”,值:10},
{name:“test-b”,值:10},
],
},
},
{
id:2,
选项:{
a:[
{name:“test-a”,值:10},
{name:“test-b”,值:10},
],
b:[
{name:“test-a”,值:10},
{name:“test-b”,值:10},
],
},
},
];
我想减少数组以仅获取
选项
属性内容并汇总项目。看起来是这样的:

const myNewArray={
a:[
{name:“test-a”,值:10},
{name:“test-b”,值:10},
{name:“test-a”,值:10},
{name:“test-b”,值:10},
],
b:[
{name:“test-a”,值:10},
{name:“test-b”,值:10},
{name:“test-a”,值:10},
{name:“test-b”,值:10},
],
};
我试过了,但我知道这根本不是正确的方法:

const myArray=[
{
id:1,
选项:{
a:[
{name:“test-a”,值:10},
{name:“test-b”,值:10},
],
b:[
{name:“test-a”,值:10},
{name:“test-b”,值:10},
],
},
},
{
id:2,
选项:{
a:[
{name:“test-a”,值:10},
{name:“test-b”,值:10},
],
b:[
{name:“test-a”,值:10},
{name:“test-b”,值:10},
],
},
},
];
常量myOptions=myArray.map((点)=>point.options);
const combinedOptions=myOptions.reduce((option)=>(option={…option}));

console.log(组合选项)向我们展示您的尝试。因此,这不是一个免费的代码编写服务。这里的目的是让你发布你解决自己问题的尝试,当这些尝试没有达到预期效果时,其他人会提供帮助。请参阅和
array。您要查找的是reduce
。您的代码更新似乎执行了要求“否”的操作?如果不提供更多details@charlietfl不,它没有,因为我想得到财产a的所有值,即使是双倍的。但有了这个,我只得到了第一个选项。