While implementing tasks such as drag-and-drop, selecting multiple files using input elements, we may want to iterate through the FileList provided to us by the browsers. When we try to use  forEach on this FileList, we get the error message “.forEach is not a function“.

Few things in JavaScript may look like an array but they are not exactly arrays. For example arguments inside functions and FileList. These are Iterable Objects with length and 0, 1, 2 etc., properties which can be iterated by using for/of or spread(…) operator.


Using for/of with FileList in JavaScript DOM

Copy to Clipboard

Using Spread Operator (…) to convert FileList to an Array in JavaScript

Copy to Clipboard