---
title: "How to use reduce to double the elements of an array in Javascript?"  
description: "How to use reduce to double the elements of an array in Javascript?"  
author: "Amrita Bhattacharjee"  
published: 2023-03-27  
updated: 2023-03-28  
canonical: https://www.mindstick.com/forum/157607/how-to-use-reduce-to-double-the-elements-of-an-array-in-javascript  
category: "javascript"  
tags: ["javascript", "javascript library", "javascript object", "array", "array list"]  
reading_time: 2 minutes  

---

# How to use reduce to double the elements of an array in Javascript?

How to use reduce to double the [elements](https://www.mindstick.com/forum/1440/wpf-button-with-multiple-text-elements) of an [array](https://www.mindstick.com/articles/335/jagged-array-in-c-sharp-dot-net) in [Javascript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript)?

## Replies

### Reply by Amrita Bhattacharjee

To use the reduce method to double the elements of an array,we can use the following code:

```javascript
const arr = [1, 2, 3, 4, 5];

const doubledArr = arr.reduce((acc, curr) => {
  acc.push(curr * 2);
  return acc;
}, []);

console.log(doubledArr); // [2, 4, 6, 8, 10]
```

Here , we have used arr to define the values of an array. After this we used the reduce method on the specific array elements through using a pass in callback function being the first argument.

The callback function is consisting with two of the acc which is used for accumulator and curr which is used for current element.

Here we used the push method in the callback function to push the doubled value of the curr into acc.Then we returned the accumulator array.

The second argument is passed to the reduce is considered as an empty array that is being as initial level value of the acc.It shows that the initial call to the callback function has an accumulator value of the empty array and a currrent element value of the initial element in the original array.

The final output of using the reduce method is an array consisting of the doubled values of the original array.


---

Original Source: https://www.mindstick.com/forum/157607/how-to-use-reduce-to-double-the-elements-of-an-array-in-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
