# Complete Array Iteration (v3)

## Preparation HTML

``````<script>
Array.prototype.forEach1 = function(callback, thisArg) {
var T = thisArg || this,
k = 0,
O = Object(T),
len = O.length >>> 0;
while (k < len) {
var kValue;
if (k in O) {
kValue = O[k];
callback.call(T, kValue, k, O);
}
k++;
}
};
</script>``````

## Test runner

Testing in
TestOps/sec
For
``````var z = [],
a = [2, 3, 4, 5, 6];
for (i = 0; i < a.length; i++) {
if (a[i] > 3) z.push(a[i]);
}``````
While
``````var z = [],
a = [2, 3, 4, 5, 6],
l = a.length;
while (l--) {
if (a[l] > 3) z.push(a[l]);
}``````
Compat forEach
``````var z = [];
[2, 3, 4, 5, 6].forEach1(function(e, i, a) {
if (e > 3) z.push(e);
});``````
Filter
``````var z = [];
[2, 3, 4, 5, 6].filter(function(e, i, a) {
return e > 3;
});``````
Map
``````var z = [];
[2, 3, 4, 5, 6].map(function(e, i, a) {
return e > 3 ? e : undefined;
}).join(" ").trim().split(" ");``````
Foreach
``````var z = [];
[2, 3, 4, 5, 6].forEach(function(e, i, a) {
if (e > 3) z.push(e);
});``````
For in
``````var z = [],
a = [2, 3, 4, 5, 6];
for (i in a) {
if (a[i] > 3) z.push(a[i]);
}``````
For (length cached)
``````var z = [],
a = [2, 3, 4, 5, 6];
for (i = 0, count = a.length; i < count; i++) {
if (a[i] > 3) z.push(a[i]);
}``````
For (backwards)
``````var z = [],
a = [2, 3, 4, 5, 6];
for (i = a.length - 1; i >= 0; i--) {
if (a[i] > 3) z.push(a[i]);
}``````