I am struggling with an array of objects:
let data = [{
createdDate: "2222",
email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="087c6d7b7c3d487c6d7b7c266b6765">[email protected]</a>",
histories: [],
meta: {
profilePic: "test"
},
name: {
first: "Vikash",
last: "Grv"
},
role: {
id: "123",
name: "test role 2"
},
specialities: [],
status: "active",
__v: 0,
_id: "123"
},
{
createdDate: "2222",
email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a3d7c6d0d796e3d7c6d0d78dc0ccce">[email protected]</a>",
histories: [],
meta: {
profilePic: "test"
},
name: {
first: "Vikash",
last: "Grv"
},
role: {
id: "123",
name: "test role 2"
},
specialities: [],
status: "active",
__v: 0,
_id: "123"
},
{
createdDate: "2222",
email: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="92e6f7e1e6a7d2e6f7e1e6bcf1fdff">[email protected]</a>",
histories: [],
meta: {
profilePic: "test"
},
name: {
first: "Vikash",
last: "Grv"
},
role: {
id: "123",
name: "test role 2"
},
specialities: [],
status: "active",
__v: 0,
_id: "123"
},
]
Now, I aim to form another array of objects as follows:
const newData = [{
teamMember: 'Vikas Grv',
email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="86f2e3f5f2b3c6f2e3f5f2a8e5e9eb">[email protected]</a>',
role: 'test role 2',
assignedOn: null
}, {
teamMember: 'Vikas Grv',
email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e195849295d4a195849295cf828e8c">[email protected]</a>',
role: 'test role 2',
assignedOn: null
},
{
teamMember: 'Vikas Grv',
email: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b2c6d7c1c687f2c6d7c1c69cd1dddf">[email protected]</a>',
role: 'test role 2',
assignedOn: null
}
]
The values in the team member field are a combination of the first and last names, emails stay the same, roles come from the key value 'name' under role, and assignedOn is set to null.
Any suggestions on how to achieve this transformation?