JSPerf is a horrible place to benchmark these things, see http://mrale.ph/blog/2012/12/15/microbenchmarks-fairy-tale.h... and http://mrale.ph/blog/2013/08/14/hidden-classes-vs-jsperf.htm... by Vyacheslav Egorov (worked on v8)
For example:
if(array.length > 0) doFunction(array[0]);
array.slice(1).forEach(doOtherFunction);
Is far more readable and maintainable than that mess with the useless indexes and does the same thing.Optimizing based on microbenchmarks and not checking for deopts and doing profiling is worthless.
I agree 1000-fold that the Array manipulation techniques are extremely easy to read. Keep in mind though, you are creating a new copy of the [1-n]array through the slicing, and the overhead of the function call with forEach will matter on large Arrays. Really depends what you are building. Don't call performance optimization worthless.
Micro benchmarks are not how we optimize - we profile.
In this particular case I am not sure I would prefer slicing+forEach to writing a old-style for-loop on any relatively hot path. Of course either profiling or thorough knowledge of the code should be applied before making this decision to determine whether this code path is hot or not, what's the average size of the array and so on. The main motivation for this decision would be the fact that slice produces the copy of the array. This is both hindrance in terms of performance (as VMs right now would not elide copy operation) and in terms of readability (e.g. when I see such code I would have to ask myself: does doOtherFunction require fresh copy or not, does it use only the first argument or all of what forEach passes into it and so on?).
So you can see the choice for me is pretty complicated.
Effectively, you're checking 'the performance of interperted JavaScript' most the the time.
2n implies looping twice or something, not a single extra operation.
(and 20 is probably a gross underestimate if we're comparing console.log to a mere ==)
Both the different types and the delete (array with holes) are _very_ harmful for performance in v8.