which for loop has better performance in javascript?
Not sure if this is a right fit for this site, as this is clearly not 'real' code, but let me give you an answer anyway.

First, in your test code, the "for" case is clearly set up incorrectly. It should look more like this:

for (let i = 0; i &lt; array1.length; i++) {
  console.log(array1[i]);
}


Second, I don't think you are asking the right question. This is clearly a case of premature optimisation. There will be differences obviously, but in real life situations the difference will probably be marginal. It is much wiser to optimise for readability and developer comfort when writing code. Use the loop that makes most sense for you in your current situation. If you run into performance issues you can start looking at optimising then, but not before.

There are too many variables to draw conclusions from your test case. The size of the array you loop over for instance. On large arrays for will be probably be fastest (probably even a bit slower than a while loop). On small arrays a forEach is possibly faster, unless you do complex operations inside the loop. And all that is dependant on the javascript engine implementation and the hardware it runs on.

So as I said, don't worry about this stuff before you run into performance issues. And when you do, test your performance with real code and real data, not oversimplified testcode.