코드:
결과보기 »
<!DOCTYPE html> <html lang="ko"> <head> <meta charset="UTF-8"> <title>JavaScript Array Object</title> </head> <body> <h1>reduce() 메소드</h1> <script> var arr = [1, 2, 3, 4, 5]; function sumOfValues(x, y) { return x - y; } document.write(arr.reduce(sumOfValues)); // 1 - 2 - 3 - 4 - 5 = -13 </script> </body> </html>