for loop performance

Performance Check On Different Type Of For Loops Available In The Javascript

source For loops plays a major role in the software development irrespective of any programming language and a small mistake in the loop might collapse the entire application so we should be really careful while handling go to link for loops.

go here In this post, We will look into different for loops and performance of each for loops available in the javascript. To Measure the performance we are going to use jsperf.

source url Description of jsperf as mentioned on their website.

affair married man single woman jsPerf — JavaScript performance playground!!

go jsPerf aims to provide an easy way to create and share test cases, comparing the performance of different JavaScript snippets by running benchmarks.

Let’s check different for loops available in the Javascript and finally, we will analyze the performance of each code snippet.

for loop

do you need a prescription for singulair Ordinary for loop, Based on the length we will iterate through each element and we will access it using its index.

cymbalta duloxetine 60 mg var loopArrayVariable = new Array(10000); loopArrayVariable.fill(1); for (i = 0; i < loopArrayVariable.length; i++) { console.log(loopVariable); }

cialis 20 mg 36 hours Note: If the loop is not proper we may end up in accessing data with out of the bound index.


Using for..each we can iterate through each and every element in an array. Easy to use.

var loopArrayVariable = new Array(10000);




The for…of statement creates a loop iterating over iterable objects.

var loopArrayVariable = new Array(10000);

for (let loopVariable of loopArrayVariable) {



The for…in statement iterates over the enumerable properties of an object.

var loopArrayVariable = new Array(10000);

for (let loopVariable in loopArrayVariable) {

Performance Results

To check the performance, I have implemented 10000 iterations on above for loop types.

Javascript For loop performance

Based on Jsperf emulation performance result.

  1. for…in
  2. for…of
  3. for…each
  4. ordinary for loop



There are different types of for loops available with ES6 Standards. the see url for…of statement should be preferred whenever possible.

Even though for…in statement got better performance, it includes few unwanted prototypes properties so it should not be used for looping.

s inscrire sur site de rencontre Prefer for…of over for…in whenever possible.

Want to some more best practices in Javascript. check here.

If you enjoyed this article, please share with your developer friends. Thanks for reading.