Question:
When iconsole.log
the output from getSpecificMonitorNews(url);
i get the actual results. But when i use return await getSpecificMonitorNews(url);
, the first results are overwritten by the last result received.Answer:
newsContents
is a global variable so its value changes. You’re returning a reference to that global object, not a copied version (and there’s no need to copy it if you just bring it inside the function).So you can either move
newsContents
inside the function if you don’t need it elsewhere:newsContents
variableIf you have better answer, please add a comment about this, thank you!