Why can't fetch data be assigned to a variable?
console.log on line 17 will print an empty array to the console:
However, when you call console.log (users), but already in the browser debugger, the desired array will be sent to the console:
Because they haven't been received yet. What is inside
thenwill be executed sometime later, and
console.log (users)will be executed immediately after the call (but not the end of the request)
Read about asynchrony.Anonymous
To place the code, please use CodePen or similar tool. Thanks you!