JS中的还原对象错误行为?

问题描述 投票:1回答:2

我使用以下减少:

const data = this.forms.reduce((accumulator, current) => {
       return (accumulator[current.name] = current.value);
      }
    }, {});

this.forms在哪里:

[
{value: {document: "fsfsf", seria: "fsfsfsf"}, "name": "Form1"}, 
{value: {seria: "AA", age: "45"}, "name": "Form2"},
{value: {marry: "yes", hobby: "AAA"}, "name": "Form3"}
]

我需要建立此结果:

{
   "Form1":  {document: "fsfsf", seria: "fsfsfsf"},
   "Form2":  {seria: "AA", age: "45"},
   "Form3":  {marry: "yes", hobby: "AAA"}
}

但是我得到错误的结果:

{
   {document: "fsfsf", seria: "fsfsfsf"},
   "Form2": {}
}

我不明白为什么?

javascript typescript
2个回答
2
投票

current.value

© www.soinside.com 2019 - 2024. All rights reserved.