将数组映射到数组的对象内部

问题描述

所以我有一个包含很多键的对象数组,像这样:

[
 { id: 1,phoneNumber: 12345,name: "John",underLicense: true
 },{ id: 2,name: "Jane",underLicense: false
 }
]

我希望它看起来像这样:

[
 { listPhone: [
    { number: 12345,underLicense: true
    },{ number: 12345
      underLicense: false
    }
  ]
 }
]

为此,我先执行map(),然后将其推入listPhones

这是我的功能

  saveLicense() {
    const listPhone = this.toSend.map(x => {
      return {
          number: x.phoneNumber,underLicense: x.underLicense
        };
    });
    const savedPhones = [];
    savedPhones.push({listPhone: listPhone});
  }

问题是,在map()方法中是否有方法可以使用它,而无需在第二步中使用push

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)