# Loop iteration (length comparison variations) (v19)

## Description

Comparison of different ways to treat the length of an array when iterating the array.

## Setup

``````window.list = [];
var x = 10000;
for (var y = 0; y < x; y++) {
window.list[y] = true;
}``````

## Teardown

``````
delete window.list;
``````

## Test runner

Testing in
TestOps/sec
Using list.length
``````for (var i = 0; i < window.list.length; i++) {
var fruit = window.list[i];
}``````
Using static len - outside for declr.
``````var len = window.list.length;
for (var i = 0; i < len; i++) {
var fruit = window.list[i];
}``````
Using static len - inside for declr.
``````for (var i = 0, len = window.list.length; i < len; i++) {
var fruit = window.list[i];
}``````
Reverse Loop (for)
``````for (var i = window.list.length; i--;) {
var fruit = window.list[i];
}``````
Reverse Loop (while)
``````var i = window.list.length;
while (i--) {
var fruit = window.list[i];
}``````
Reverse Loop (for) w/ outside declaration & --
``````var i = window.list.length;
for (; i--;) {
var fruit = window.list[i];
}``````
Reverse Loop (for) w/ outside declaration & >= 0
``````var i = window.list.length,
fruit;
for (; i >= 0; i--) {
fruit = window.list[i];
}``````
Destructive array - shift
``````var list = window.list.slice(0),
fruit = list.shift();
while (fruit) {
fruit = list.shift();
}``````
Destructive array - pop
``````var list = window.list.slice(0),
fruit = list.pop();
while (fruit) {
fruit = list.pop();
}``````
``````var list = window.list.slice(0).reverse(),