Find the Minimum and Maximum Element in an Array Using Javascript With HTML

Certainly! You can use JavaScript to find the minimum and maximum elements in an array. Here’s an example code snippet with HTML:

<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Find Min and Max</title>
// Function to find minimum and maximum elements in an array
function findMinAndMax(arr) {
if (arr.length === 0) {
return { min: undefined, max: undefined };
let min = arr[0];
let max = arr[0];
for (let i = 1; i < arr.length; i++) {
if (arr[i] < min) {
min = arr[i];
if (arr[i] > max) {
max = arr[i];
return { min, max };
// Example usage
const numbers = [3, 1, 7, 4, 2, 8, 5];
const result = findMinAndMax(numbers);
console.log("Array:", numbers);
console.log("Minimum:", result.min);
console.log("Maximum:", result.max);

In this example, the `findMinAndMax` function takes an array as input and iterates through it to find the minimum and maximum elements. The result is then logged to the console. You can adapt this code to display the result on your webpage as needed.