I think your code is some kind of strange.
When you track the code:
Promise.allSettled()
takes an array generated from the map
method
- The array generated from the
map
method in fact contains objects and not promises, and that's because you resolve the promises already in that map
method, so the values inside the array passed to Promise.allSettled()
are just objects.
- And when the
Promise.allSettled()
takes inside its array any value that's not a promise, it consider that value as a resolved promise already and will put that value in the array of results that you can get in the .then()
handler.
- So the results array will contains its normal objects with a resolved promises each value will be the object passed to it, and all status is
fulfilled
So, you can imagine that your Promise.allSettled()
takes an array like that:
let allData = Promise.allSettled([
{ name: "myName1", status: "fulfilled", res: "" },
{ name: "myName2", status: "fulfilled", res: "" }
])
So, it will consider the two objects as a resolved promises, then if you handle that promise like that:
allData.then((results) => {
console.log( results )
})
You will find this result:
[
{status: "fulfilled", value: { name: "myName1", status: "fulfilled", res: "" }},
{status: "fulfilled", value: { name: "myName2", status: "fulfilled", res: "" }}
]
Now I think it's clear to you, what your code is ready does.
Let's come to the main question,
Can I handle the object returned in the array of result in the
Promise.allSettled()
And the answer is No
for sorry, because this is something in the builtin structure of Promise.allSettled()
that it works with.
But you can structure the object in the value of the object that returned by the Promise.allSettled()
I hope I helped you understand that.