You can find the highest number in an array in JavaScript
using the Math.max
and
DSA algo
// Neel.B
const givenArray = [2,3,12,44,98,55]
let firstElement = givenArray[0] // assume it's highest
let arrayLength = givenArray.length
for(let count = 1; count < arrayLength; count++) {
if(givenArray[count] > firstElement) {
firstElement = givenArray[count]
}
}
console.log(firstElement) //output : 98
//OR
console.log(Math.max(...givenArray))
© www.thecoderjob.com. All Rights Reserved. Designed by HTML Codex