
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Finding product of an array using recursion in JavaScript
We are required to write a JavaScript function that takes in an array of Integers. Our function should do the following two things −
Make use of a recursive approach.
Calculate the product of all the elements in the array.
And finally, it should return the product.
For example −
If the input array is −
const arr = [1, 3, 6, .2, 2, 5];
Then the output should be −
const output = 36;
Example
The code for this will be −
const arr = [1, 3, 6, .2, 2, 5]; const arrayProduct = ([front, ...end]) => { if (front === undefined) { return 1; }; return front * arrayProduct(end); }; console.log(arrayProduct(arr));
Output
And the output in the console will be −
36
- Related Articles
- Finding smallest number using recursion in JavaScript
- Finding Fibonacci sequence in an array using JavaScript
- Find the middle element of an array using recursion JavaScript
- Finding the Largest Triple Product Array in JavaScript
- Finding the product of array elements with reduce() in JavaScript
- Finding the only unique string in an array using JavaScript
- Finding the rotation of an array in JavaScript
- Finding the mid of an array in JavaScript
- Finding degree of subarray in an array JavaScript
- JavaScript Recursion finding the smallest number?
- Finding greatest digit by recursion - JavaScript
- Using recursion to remove consecutive duplicate entries from an array in JavaScript
- Finding product of Number digits in JavaScript
- Array flattening using loops and recursion in JavaScript
- Using recursion to remove consecutive duplicate entries from an array - JavaScript

Advertisements