I will simply write down my thoughts below
function demo(){
let data=[];
fetch(xxx).then((res)=>{
data.push(res);
})
return data;
}
Since it is an asynchronous request, the returned data is still an empty array, not an array containing the requested data. So is there any way to get the data and then return it?
It is impossible to return the value asynchronously
Values can only be processed in callback functions
Use async/await method
Then execute the function
Use await, pay attention to the need to build
Refer to es6 await