Please, how can I save output of fetch to a variable - to be able to work with it as with an object?
Here is the code:
var obj;
fetch("url", {
method: "POST",
body: JSON.stringify({
"filterParameters": {
"id": 12345678
}
}),
headers: {"content-type": "application/json"},
//credentials: 'include'
})
.then(res => res.json())
.then(console.log)
The final console.log
will show an object. But when I tried to save it to variable .then(res => obj = res.json())
than the console.log(obj)
will not hold the Object, but the Promise.
Any idea please, how to turn it into an Object saved in the variable?