TypeScript Bits are small, easily digestible pieces of information to encourage TypeScript/JavaScript best practices. From beginner, to intermediate, to ninja, these bits are for you 😄
Estimated reading time : 2 minutes
For loops are for loops, sure. There is absolutely nothing wrong with the traditional incremental iterator approach. However, this recommendation is about readability, maintenance, decreasing code smells, as well as best practice when using loops in TypeScript (and in this case ES6+ as well). Often during code review one will find references to an item via its parent array and index numerous times (think myArray[i].firstName and guess how lastName is accessed? :disappointed:). It is a best practice in most if not all languages to create a variable out of this value accessed by index once.