Q:

Having problems understanding the result mixing "For loops" and "array" (beginner)

I'm currently studying javascript and I don't understand the result based on a specific condition. Thanks for you patience with newbies like myself ;)
In the following case, I don't understand why the last line "blue" is displayed since the condition is "show only when counter > 0".
var table = ['blue','yellow','orange','red'];
for (var counter = table.length ; counter > 0 ; counter--)
{
document.write(table[counter-1] + "<br>")
}

Another way to see the result would be :
var table = ['blue','yellow','orange','red'];
document.write(table[table.length-1] + '<br>'); // result: table[3] "red"
document.write(table[table.length-2] + '<br>'); // result: table[2] "orange"
document.write(table[table.length-3] + '<br>'); // result: table[1] "yellow"
document.write(table[table.length-4] + '<br>'); // result: table[0] "blue" = should not be displayed if we have the condition 'counter > 0'

Thanks for your help!

A:

Because you are using - 
var table = ['blue','yellow','orange','red'];
for (var counter = table.length ; counter > 0 ; counter--)
{
    document.write(table[counter-1] + "<br>") //when table has 4 item, counter = 1, counter > 0, table[counter - 1] = table[0]
}

In other words, your code perfectly prints all. If you wish to skip the last one do this - 
var table = ['blue','yellow','orange','red'];
for (var counter = table.length - 1; counter > 0 ; counter--)
{
    document.write(table[counter] + "<br>")
}

