I've been looking for a simple method to iterate through nodelists, and I've always found it frustrating that I can't just use forEach
directly on nodeLists.
Instead, I've come up with this approach:
Array.prototype.forEach.call(nodeList, callback)
.
For obtaining the index, I utilize:
Array.prototype.indexOf.call(nodeList, node)
.
In fact, I tend to rely on Array.prototype for many operations involving nodeLists.
But I can't help but wonder if these methods are considered unconventional workarounds?
Is there a more proper way to achieve the same results?
Moreover, assuming that I don't actually require an array from nodeList, would using
Array.from(nodeList).forEach(callback)
offer any benefits?