The new for loop in jQuery 3

Roller Coaster

Love the fact that the for loops are now iterations in jQuery. The old way of doing loops like this:

var $elements = $(".myclass");
for (var x=0; x< $elements.length; x++){

Can now look like this in jQuery 3:

var $elements = $(".myclass");
for (var element of $elements){

9 thoughts on “The new for loop in jQuery 3”

  1. I’d prob stick with an Each loop as being less code. Wonder the rationale behind this syntax – first glance looks like a strange hybrid of For and Each loop – although don’t really see the value, unless planning to phase out Each!


Leave a Reply

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

You are commenting using your 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 )

Google+ photo

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

Connecting to %s