by qwertox · 5y ago · 0 comments
Sometimes I can use Array.forEach() and sometimes not, and I don't know why, even if I'm only using Chrome. So I just use lodash.
Spread syntax is my goto for that:
[...arrayish].forEach(...)
But, it being JavaScript, there’s probably a subtle distinction in where Array.from(arrayish) works and where [...arrayish] works.`...foo` requires `foo` to be an iterable (implements the iterator known symbol).
`Array.From()` only requires it to be array-like and not necessarily iterable.
for (const item of iterable) {
// do forEach stuff here
}