Given an array as input,find the largest number in the array.Using Javascript

let arr=[5,18,26,30,40,6];
    function largest(arr)
     {
        let i;
        let max = arr[0];
        for (i = 1; i < arr.length; i++)
         {
            if (arr[i] > max)
                max = arr[i];
        }
        
    return max;
}
    
    
    console.log('Max='+largest(arr));
    

Leave a Comment

Your email address will not be published. Required fields are marked *