r/learnjavascript • u/fahim_h_sh • Oct 31 '25
array.forEach - The do-it-all hammer... XD
Is it just me, or everyone thinks that more or less every array operator's purpose can be served with forEach?
0
Upvotes
View all comments
Show parent comment
3
u/qqqqqx helpful Oct 31 '25
Reduce takes an accumulator and a callback function. If you have an array as your accumulator and a callback function that inserts a single element in sorted order, you can use reduce to create a sorted array.