The other day I was scraping some information from the Dropbox site. The content was comments on my second draft on my book Loose Candy- which (at the time, this might have changed) were not downloadable. I had gotten feedback through various sources and I wanted to collect everything in one place.
One might think that the return value from ’ .getElementsByClassName()’ function (or other DOM interface functions) would be enumerable and behave like an array- but it’s not. It’s not an array, and it does not have a foreach() function. A -foreach call would yield:
Uncaught TypeError: result .foreach is not a function
The fix is easy. ECMAScript 6 has an Array.from() function that takes any array-like or iterable object and turns it into an array.
Instead of result.foreach()
You can could do:
For more on arrays, NodeList and HTMLCollection read this discussion on StackOverflow