Currently, I am delving into the world of promises for the very first time. My goal is to retrieve data (in the form of an array) from two distinct endpoints. Consequently, I have drafted the following code. Upon inspecting my console, I notice that [Promise, Promise]
both appear in a resolved state. Interestingly, I can witness the desired response within the data
property; however, I remain unsure about how to retrieve this crucial data array. Can anyone provide guidance on accessing the data array from these promises? Thank you.
Console Output Regarding Promises
0: Promise
[[PromiseStatus]]: "resolved"
[[PromiseValue]]: "Object"
data: {room 18: {...}, room 19: {...}, room20: {...}} // target data content
1: Promise
[[PromiseStatus]]: "resolved"
[[PromiseValue]]: "Object"
data: {room 18: {...}, room 19: {...}, room20: {...}} // target data content
const urls = ['/room/*/userconfig', '/room/*/observation/latest'];
let requests = urls.map(url => axios.get(url));
Promise.all([requests])
.then(res => res.map(response => console.log(response) // create 1 array and match roomId data))