• 코드:
​x
 
1
<!DOCTYPE html>
2
<html lang="ko">
3
​
4
<head>
5
    <meta charset="UTF-8">
6
    <title>JavaScript Array Object</title>
7
</head>
8
​
9
<body>
10
​
11
    <h1>reduceRight() 메소드</h1>
12
​
13
    <script>
14
        var arr = [1, 2, 3, 4, 5];
15
        function sumOfValues(x, y) {
16
            return x - y;
17
        }
18
​
19
        document.write(arr.reduceRight(sumOfValues));   // 5 - 4 - 3 - 2 - 1 = -5
20
    </script>
21
    
22
</body>
23
​
24
</html>