Phương thức reduceRight() duyệt mảng từ cuối về đầu, áp dụng hàm callback lên tích lũy (accumulator) và phần tử hiện tại, trả về giá trị đơn lẻ.
Tham số:
- callback – Hàm nhận (accumulator, currentValue, index, array).
- initialValue (tùy chọn) – Giá trị khởi tạo cho accumulator.
Ví dụ
<html>
<head>
<title>JavaScript Array reduceRight Method</title>
</head>
<body>
<script>
var total = [0, 1, 2, 3].reduceRight(function(a, b) { return a + b; });
document.write("total is: " + total); // 6
</script>
</body>
</html>