How to return data obtained using the fetch?

Good time of day.
There is a Fetch request :
let data = fetch('some url')
.then(
 response => response,
 error => alert(`Rejected: ${error}`)
 );

How do I put the request body (json) into a variable data and use it in another file?
June 8th 19 at 17:26
1 answer
June 8th 19 at 17:28
Solution
var data = null;
fetch('some url')
.then(
 response => {
 data = response;
},
 error => alert(`Rejected: ${error}`)
 );

But the data is in the variable data only on completion of the request. Maybe it makes sense to call the function and pass data as a parameter, for example, like this:
fetch('some url')
.then(
 response => {
someFunc(response);
},
 error => alert(`Rejected: ${error}`)
);

someFunc(data) {
alert(data);
}


Then she will be executed for the completion of the request, and will not have cecati data on the availability of data. That is, actions will be executed sequentially.
Thank you, understood. Before a conclusion is not converted to Json - kelsie_Bogisich commented on June 8th 19 at 17:31

Find more questions by tags JavaScript