[].forEach, Todd Motto, & coding with intent
If you are a front end developer, you most likely know and appreciate Todd Motto. I do for sure. A while back (2014) he blogged about his opinion on using forEach and how he thought it was a hack [read here]. Below are my thoughts on his article and a differing view on coding with intent.
Realize this is an older post, but isn't using the forEach function considered coding with intent – as it is meant to be used with an object collection? From the docs: "Invokes the iterator function once for each item in obj collection, which can be either an object or an array..." The only issue I see, is your choice in trying to use it for arrays that are not object collections. At your status, declaring this to be a hack because you don't like it, is misleading and misguidance for folks who are not as advanced in the understanding of good code practices. The forEach function is not intended to replace a "for loop", it is specifically for working with objects. By coding with intent, other developers can quickly understand what data is being worked on. And there is nothing hip or hipsterish about coding.










