I have past experience with Promises and Fetch calls in JavaScript but I just can't seem to figure this out.
I am trying to fetch data from a site and store a part of the header as shown below:
async function getData() {
let response = await fetch("url.....", requestOptions);
let data = await response.headers.get('set-cookie')
return data;
}
async function main()
{
const dataset = await getData();
console.log(dataset) // This here prints out the data AFTER everything has ran, makes sense as it probably waits for the promise to be resolved.
data = dataset // This does not set the value of data to dataset. It sets it to Promise <Pending>
}
main();
So from here how can I finally set the variable Data to the resolved promise? I thought the 'await getData()' would wait for the promise to be resolved before continuing, thus allowing data to be set to an actual value and not a promise.