Some terse syntax of for loops in JavaScript.

  • For Actual Arrays,  currently (ES5+) have three options and will soon have two more in (ES6+) 

  1. Use forEach (ES5+)
  2. Use a simple for loop
  3. Use for-in correctly :-- This approach is best when you have sparse array.
  4. Use for-of (use an iterator implicitly) (ES6+)
  5. Use an iterator explicitly (ES6+)
  • For Array-Like Objects

So for instance, if you want to use forEach on the NodeList returned by querySelectorAll, you can do this:
var divs = Array.prototype.slice.call(document.querySelectorAll("div"), 0);
divs.forEach(function(div) {
    // Use each div here
});

jQuery.each(arr, function(index, value) { ... }