简体   繁体   English

如何使用由先前对象数组的两个键组成的键条目创建新的对象数组

[英]How to create new array of objects with key entrie made from two keys of previous array of objects

const users = [
      {
        firstName:"Name",
        lastName:"Last Name"
      },
      {
        firstName:"Name",
        lastName:"Last Name"
      },
       {
        firstName:"Name",
        lastName:"Last Name"
      }
  ];

I want to get new array of objects with these properties我想获得具有这些属性的新对象数组

const updatedUsersObject = [
    {
    fullName:"Name Last Name"
  },
  {
    fullName:"Name Last Name"
  },
   {
    fullName:"Name Last Name"
  }
]

I've tried with我试过了

const updatedUsersObject = users.map(user=>{
  return user.firstName+" "+user.lastName;
});

But that is only returning array of full names.但这只是返回全名数组。

 const users = [ { firstName:"Name", lastName:"Last Name" }, { firstName:"Name", lastName:"Last Name" }, { firstName:"Name", lastName:"Last Name" } ]; console.log(users.map(item => ({fullName: `${item.firstName} ${item.lastName}`})));

const updatedUsersObject = users.map(
    (user) => ({
        fullNameid: user.firstName+' '+user.lastName
    })
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM