This particular array is currently empty. The specific contents of the array are not important; what does matter is that it needs to be an array in order to utilize the forEach
method. Instead of creating and extracting forEach
from an empty array, you can simply use Array.prototype.forEach
.
This method is commonly employed when dealing with an object that resembles an array (such as a NodeList
; having properties like length
, 0
, 1
, 2
, etc.) but isn't actually an array. Although these "array-like" objects lack standard array methods, by utilizing the appropriate context (this
) through call
, you can still make the array methods function correctly.
In this case, because you're working with a legitimate array rather than an array-like object, you can directly call the forEach
method, for example: lists.forEach(...)
.