this is my given array
const arr=[5,10,4,24,13,8]
- *largest is set to first element in the array --- largest = arr[0] *
- You need to set the first element to largest
- next need to loop from 1 st index to last index
- in each loop check if the array value is larger than that in that case largest will be the current iterating element
Program to find the largest element in the array
let largest = arr[0];
for(let i=1;i<arr.length;i++){
if(arr[i] > largest){
largest=arr[i]
}
}
console.log(largest)
Top comments (0)