Uncaught TypeError: aArray.forEach is not a function

You’ve got an array, you’re trying to loop and lo-and-behold, you come up against this error:

(index):116 Uncaught (in promise) TypeError: aArray.forEach is not a function

You’re looping an array, so how can this be?

The most common cause is actually trying to loop arround an array-like collection rather than an array itself. For example, a HTMLCollection is array-like, not an array.

Simple fix for this is to create an array from this collection using code such as:

Array.from(aArray).forEach(function(item, index){
   //your code here

You may also like...

3.8 4 votes
Article Rating
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x
%d bloggers like this: