I'm using promise.AllSettled to fetch data from 2 / 3 endpoints and result looks like this
Simplified results array
const results = [
{
value: {
payload: {
email: "[email protected]",
first_name: "",
last_name: "",
pk: 183,
username: "faker",
}
},
error: true,
},
{
value: {
payload: {
avatar: "https://cdn.zeplin.io/faker.png",
email: "[email protected]",
id: 183,
is_admin: false,
username: "faker",
}
},
error: false
}
]
I would like to get flat object that contains something like this, but generated dynamically (the number of the payloads may vary)
const desiredObj = Object.assign({}, results[0].value.payload, results[1].value.payload)
/*
avatar: "https://cdn.zeplin.io/faker.png",
email: "[email protected]",
first_name: "",
id: 183,
is_admin: false,
last_name: "",
pk: 183,
username: "faker"
*/
Object.assign({}, ...results.map(x => x.value.payload))?