array.reduceright() is a built-in function in javascript that converts the elements of a given array from right to left into a single value. So let's take a look at the specific use of the reduceRight function.
Let’s take a look at the basic syntax of the reduceRight function
array.reduceRight(previousValue, currentValue)
The two parameters previousValue and currentValue represent the previous sum of the given input array The current element.
Let’s look at two specific examples
Example 1:
The code is as follows
<!DOCTYPE html> <html> <head> <title></title> </head> <body> <script> const A = [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8 ] ]; a = A.reduceRight((previousValue, currentValue) => previousValue.concat(currentValue)); document.write(a); </script> </body> </html>
The output result is: 7,8,4,5 ,6,1,2,3
Example 2:
The code is as follows
<!DOCTYPE html> <html> <head> <title></title> </head> <body> <script> const A = [ [ 1, 2, 3 ], [ "a", "b", "c" ], [ 7, 8 ] ]; a = A.reduceRight((previousValue, currentValue) => previousValue.concat(currentValue)); document.write(a); </script> </body> </html>
The output result is: 7,8,a,b,c,1,2, 3
This article has ended here. For more exciting content, you can pay attention to other related column tutorials on the php Chinese website! ! !
The above is the detailed content of How to use reduceRight function. For more information, please follow other related articles on the PHP Chinese website!