Friday, November 22, 2019

Iterating through arrays in javascript

There's a great answer in this post on stackoverflow about iterating through array entries. The answer author goes to great length to illustrate the the different methods, their pros and cons.

  1. Use forEach and related (ES5+)
  2. Use a simple for loop
  3. Use for-in correctly
  4. Use for-of (use an iterator implicitly) (ES2015+)
  5. Use an iterator explicitly (ES2015+)
Some of this information may be dated, especially when it comes to updated releases of ECMAScript.  Nevertheless, this is a link that's probably worth keeping around.