4 ms·
Isn't this faster for iterating over the elements: var a = ["banana", Math.min, 4, "apple"]; for (var i=a.length; i; i--) { console.log(a[i]); }
by svnv 16y ago
Isn't this faster for iterating over the elements:
var a = ["banana", Math.min, 4, "apple"];
for (var i=a.length; i; i--) {
console.log(a[i]);
}
- pooj 16y agoClever, but sometimes you don't want to go in reverse.
- jacksoncarter 16y agoOr try this var i = a.length; while (i--){ console.log(a[i]); }
- code_duck 16y agoYes, in a micro-optimized way.
- svnv 16y agoActually, I just realized this does not work, there is an off by 1 error here. jacksoncarter's piece of code works though.