Testing Javascript and jQuery array loops

(by axds)

https://jsfiddle.net/s7bn7cfr/

The simple for loop seems to win the speed tests:

let arrLen = test.length; for( let i = 0; i < arrLen; i++ ){  }

Although this method is less DRY as the length of the the array has to be known. JS’s forEach() or jQuery’s $.each() are good alternatives that are dynamic.

The clear worst is the ‘for x in y’ loop. Which has bulky syntax and is slow.

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s