# JavaScript tips. The .reduce method optimization

When using the .reduce method for arrays or objects, there are serious performance problems due to the internal operating mechanism of the method. 

This problem occurs when working with an array of ***thousands or more elements***, depending on the computer power. Each time the method creates a new object and transfers all the fields of the old one there, adding a new field. This transfer takes a huge amount of resources and time.

***Code example:***

![Screenshot_1213.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1654149300048/ocyIgEbJx.png align="left")

**Solution 1.** We will not recreate acc at each iteration, but add one new object property instead:

***Code example***

![Screenshot_6324.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1654149396936/1cIb-7DDh.png align="left")

**Solution 2.** Use forEach() method:

***Code example***

![Screenshot_6546756.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1654149434154/OJjXhIPHL.png align="left")

Take advantage of these methods and optimize your applications! Learn more how else we use [JavaScript and its frameworks on Twelvedevs website](https://twelvedevs.com/technologies/javascript-development)
