HTMLCollections are array-like. They are iterable and have a length property. The slice function can convert array-like objects into Arrays. this is bound to our array-like object. slice iterates over this using the length property since no other arguments were given. All the elements are returned in a new Array then we can call forEach method on our Array
Is a good solution too if not better. timestamps is bound to this then forEach method iterates over the array-like object by using the length property. My solution would have looped through the array-like object once then the newly created array versus this solution which is once.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I just want to make a few points.
forloop in years.querySelectorAll.getElementsByClassNamereturns anHTMLCollection, which is why you were getting the error.NodeLists have aforEachmethod andHTMLCollections do not.My initial instinct on circumventing this is the following:
HTMLCollections are array-like. They areiterableand have alengthproperty. Theslicefunction can convert array-like objects intoArrays.thisis bound to our array-like object.sliceiterates overthisusing thelengthproperty since no other arguments were given. All the elements are returned in a newArraythen we can callforEachmethod on ourArrayBut looking at your initial answer:
Is a good solution too if not better. timestamps is bound to
thisthenforEachmethod iterates over the array-like object by using thelengthproperty. My solution would have looped through the array-like object once then the newly created array versus this solution which is once.