Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Find the Sum of Values in an Array in JavaScript</title> </head> <body> <script> var array = [1, 2, 3, 4, 5]; // Getting sum of numbers var sum = array.reduce(function(a, b){ return a + b; }, 0); document.write(sum); // Prints: 15 </script> </body> </html>