147
rated 0 times
[
154]
[
7]
/ answers: 1 / hits: 46259
/ 11 Years ago, thu, april 18, 2013, 12:00:00
I came across a problem which I did manage to solve but I honestly do not understand how this works.
var array = [3, 6, 2, 56, 32, 5, 89, 32];
var largest = 0;
//My code
for (var i = 0; i < array.length; i++) {
if (array[i] > largest) {
largest = array[i];
}
}
console.log(largest);
How does my array assign a value to my variable within the if statement?
Why does this version not work?
array[i] = largest;
I'm very new to programming and I believe that understanding fundamental things as small as this can help many beginners become competent programmers.
More From » arrays