Certainly! You can create a JavaScript program that takes an array of numbers and returns the highest number using the
Math.max function. Here's an example:
function findHighestNumber(numbers) {
// Use Math.max to find the highest number in the array
const highestNumber = Math.max(...numbers);
return highestNumber;
}
// Example usage:
const numberArray = [12, 5, 9, 27, 4, 15];
const result = findHighestNumber(numberArray);
console.log(result); // Outputs: 27
In this example, the findHighestNumber function takes an array of numbers and uses the spread operator (...) to pass the array elements as separate arguments to the
Math.max function. This efficiently finds the highest number in the array.
The example usage demonstrates how to use the function with a sample array ([12, 5, 9, 27, 4, 15]). The result (the highest number) is then printed to the console.
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Certainly! You can create a JavaScript program that takes an array of numbers and returns the highest number using the Math.max function. Here's an example:
In this example, the findHighestNumber function takes an array of numbers and uses the spread operator (...) to pass the array elements as separate arguments to the Math.max function. This efficiently finds the highest number in the array.
The example usage demonstrates how to use the function with a sample array ([12, 5, 9, 27, 4, 15]). The result (the highest number) is then printed to the console.