Time to play with reduce()
🥳
I will try some functions with reduce()
to deepen my understanding about reduce()
Array.prototype.reduce() - JavaScript | MDN
Flatten an array of arrays
To flat single level array
!Deep level flatten is not applicable with this function
=> The alternative is Array.prototype.flat() - JavaScript | MDN (Thanks @jcubic for your comment 😉)
Play it by yourself
Top comments (2)
There is Array.prorotype.flat() that do the same and more because it can do nested arrays of any level.
Excellent point!
I have added the information 👍
And I think if you want to flatten an array, using
flat()
is more intuitive and readable than doing it withreduce()
.Anyway, thanks for your comment!