JavaScript | array.reduceRight()
The array.reduceRight() is an inbuilt function in JavaScript which is used to convert elements of the given array from right to left to a single value.
Syntax:
array.reduceRight(previousValue, currentValue)
Parameters: It accepts two parameters previousValue and currentValue which represents the previous and current element of the given input array.
Return Values: It returns the result after reduction to a single value.
Code #1:
<script> // Taking some array as the element of an array "A" const A = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; // Calling array.reduceRight() function a = A.reduceRight((previousValue, currentValue) => previousValue.concat(currentValue)); // printing result document.write(a); </script> |
Output:
7, 8, 4, 5, 6, 1, 2, 3
Code #2:
<script> // Taking some array as the element of an array "A" const A = [ [ 1, 2, 3 ], [ "a", "b", "c" ], [ 7, 8 ] ]; // Calling array.reduceRight() function a = A.reduceRight((previousValue, currentValue) => previousValue.concat(currentValue)); // printing result document.write(a); </script> |
Output:
7, 8, a, b, c, 1, 2, 3
Recommended Posts:
- Introduction to JavaScript Course | Learn how to Build a task tracker using JavaScript
- JavaScript Course | Understanding Code Structure in JavaScript
- JavaScript Course | Logical Operators in JavaScript
- JavaScript Course | Conditional Operator in JavaScript
- JavaScript Course | Data Types in JavaScript
- JavaScript Course | Printing Hello World in JavaScript
- JavaScript Course | Loops in JavaScript
- JavaScript Course | Functions in JavaScript
- JavaScript Course | JavaScript Prompt Example
- JavaScript Course | Variables in JavaScript
- JavaScript Course | Objects in JavaScript
- JavaScript Course | Operators in JavaScript
- JavaScript vs Python : Can Python Overtop JavaScript by 2020?
- How to include a JavaScript file in another JavaScript file ?
- this in JavaScript
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



