Tuesday, 20 August 2013

Finding the largest element in an Array - Javascript

Finding the largest element in an Array - Javascript

I'm trying to write a for loop that finds the largest element in the array
and log that element to the console. I got this so far but it doesn't
work. Can anyone help?
var array = [3, 6, 2, 56, 32, 5, 89, 32];
var largest = 0;
for (var i = 0; 0 < 100; i++ ) {
(if (array[i] > largest) {
largest = array[i]);
}
}
console.log(largest);
Thanks

No comments:

Post a Comment