async function test() {
const res = await fetch('https://www.easy-mock.com/mock/5c6d317e8d040716434d0a5b/reading/category/homeSmallCategory');
console.log(res) // data
return res;
}
console.log(test()) // PromiseĀ {<pending>}
setTimeout(() => {
console.log(test()) // PromiseĀ {<pending>}
})
Please parse it at the console
.
How do I deal with this problem.I want the data processing in the test
function .But it always return PromiseĀ {<pending>}
.
And then I think that I can deal with it like this.
if (res instanceof Promise) {
res.then(data => res = data);
}
I put it at the end of the test
.But it still not working.I console
the Object.prototype.toString.call(res)
.And then I get [object Array]
.I realized that inside the function
. The res
is an array not matter what.But at the outside the res
is not alike that. I know this is something about event loop
.Thanks for your help.
I am using the Google Custom Search in my web page and want to filter the results before displaying the results. I cannot find any callback in Google's documenation where I can access the results so ...
I am using the Google Custom Search in my web page and want to filter the results before displaying the results. I cannot find any callback in Google's documenation where I can access the results so ...
Is it possible to query firebase for documents in a collection where the number of elements in an array of a particular field is greater than 0 For my example, each document has-a field called '...
Is it possible to query firebase for documents in a collection where the number of elements in an array of a particular field is greater than 0 For my example, each document has-a field called '...
Introduction Hello, I'm trying to build a counter component for my online store, but I'm having trouble getting with it to function correctly. Problem From my understanding is that the count value ...
Introduction Hello, I'm trying to build a counter component for my online store, but I'm having trouble getting with it to function correctly. Problem From my understanding is that the count value ...
For example: function Constructor() { this.peoperty = 1; this.myMethod1 = function() { //do something }; this.myMethod2 = function() { let a = myMethod3(); } /*no '...
For example: function Constructor() { this.peoperty = 1; this.myMethod1 = function() { //do something }; this.myMethod2 = function() { let a = myMethod3(); } /*no '...