As a Front-end Engineer: 10 Secrets about “[].reduce” You Must Know About

10 Tricks About Reduce That Make You Write Less And Do More.

fatfish
4 min readApr 26, 2023
Photo by Timothy Meinberg on Unsplash

My good friend, as a front-end developer, you must use the reduce function a lot, it is a powerful and useful array API, but today I want to share with you 10 advanced tricks and tips about it, come on!

1. As an adder and accumulator

Using “reduce”, we can easily implement the function of adding or accumulating several numbers.

2. Calculate the max and min value of an array

How many ways do you get the maximum or minimum value of an array?

1: Using Math.max and Math.min

We have to admit that using Math’s API is the easiest way.

--

--

fatfish

Hi friends, I am a front-end engineer from Alibaba, let’s code happily together.