Write a javascript program that takes an array of numbers and returns the highest number.
Write a javascript program that takes an array of numbers and returns the highest number.
258
14-Apr-2023
Updated on 26-Nov-2023
Aryan Kumar
26-Nov-2023Certainly! 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.