Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Find Max or Min Value in an Array Using Reduce Method</title> </head> <body> <script> let numbers = [2, 5, 6, 4, 3, 7]; // Using reduce method to find max value let max = numbers.reduce(function(a, b) { return Math.max(a, b); }); document.write(max); // Prints: 7 document.write("<br>"); // Using reduce method to find min value let min = numbers.reduce(function(a, b) { return Math.min(a, b); }); document.write(min); // Prints: 2 </script> </body> </html>