0

I'm trying to perform a few tasks in a function (fetch a web-page, and perform some calculations and such), however my list of websites to visit is in an key-value paired object.

I need to find some async/await compatible alternate to forEach which will work on Object.keys().

Since Object.keys(sites).forEach(function(key, index) { ... } doesn't seem to allow async calls within it, what's the best alternative?

The loop essentially fetches multiple sites, validates the JSON data, and adds it to a an array if valid.

It then later loops over the new array via a standard for and compares the results, before returning either boolean true or false.

  • Use `for ... of` – Mark Jan 05 '20 at 16:08
  • @MarkMeyer do you have an example of this syntax with Object.keys()? Sorry I'm quite new to JS – Vekix29941 Jan 05 '20 at 16:11
  • ```for ... of``` gives me: ```Servers is not iterable```. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/is_not_iterable suggests using Object.keys() but I cannot for this as it isn't async. – Vekix29941 Jan 05 '20 at 16:26

0 Answers0