---
title: "Write a javascript program that takes a numbers array and returns the product of all the numbers."  
description: "Write a javascript program that takes a numbers array and returns the product of all the numbers."  
author: "Revati S Misra"  
published: 2023-04-14  
updated: 2023-11-26  
canonical: https://www.mindstick.com/forum/157803/write-a-javascript-program-that-takes-a-numbers-array-and-returns-the-product-of-all-the-numbers  
category: "javascript"  
tags: ["javascript", "array"]  
reading_time: 1 minute  

---

# Write a javascript program that takes a numbers array and returns the product of all the numbers.

Write a [javascript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript) [program that takes](https://www.mindstick.com/forum/157801/write-a-javascript-program-that-takes-an-array-of-numbers-and-returns-the-highest-number) a numbers [array](https://www.mindstick.com/articles/335/jagged-array-in-c-sharp-dot-net) and returns the [product](https://www.mindstick.com/articles/75385/full-product-keys) of all the numbers.

## Replies

### Reply by Aryan Kumar

Certainly! You can create a JavaScript [program](https://www.mindstick.com/blog/12337/scaling-up-your-mentorship-program) that calculates the product of all the numbers in an array by using the **reduce** method. Here's an example:

```plaintext
function calculateProduct(numbers) {
  // Use the reduce method to multiply all numbers in the array
  const product = numbers.reduce((accumulator, currentNumber) => {
    return accumulator * currentNumber;
  }, 1); // Start with an initial value of 1

  return product;
}

// Example usage:
const numberArray = [2, 3, 5, 7];
const result = calculateProduct(numberArray);

console.log(result); // Outputs: 210
```

In this example, the **calculateProduct** function takes an array of numbers and uses the **reduce** method to multiply them together. The **reduce** function takes a callback function with an accumulator (initialized to 1) and the current element of the array. The accumulator accumulates the product as the function iterates through the array.

The example usage demonstrates how to use the function with a sample array (**[2, 3, 5, 7]**). The result is then printed to the console.


---

Original Source: https://www.mindstick.com/forum/157803/write-a-javascript-program-that-takes-a-numbers-array-and-returns-the-product-of-all-the-numbers

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
