_:nd099f5dea73b42f287b2600af29b0054xb0
<http://schema.org/articleBody>
"Suppose we have elements collected using this selector:\nconst elements = document.querySelectorAll('.element'); There are several ways to create a JavaScript loop that goes over these elements.\nMethod 1: The old way for (let i = 0; i  elements.length; i++) { \t// The current element is available as \"elements[i]\". } Method 2: The new way for (const element of elements) { \t// The current element is available as \"element\". } Method 3: forEach elements.forEach((element) = { \t// The current element is available as \"element\". }); A shorter version (without defining elements as a separate const):\ndocument.querySelectorAll('.element').forEach((element) = { \t// The current element is available as \"element\". }); .aside{padding:var(--content-gap);margin-bottom:var(--content-gap);border-radius:var(--radius);border-left:var(--radius) solid #a5a5a5;background:#f5f5f5}.aside *:last-child{margin-bottom:0!important}.aside.warning{border-color:#e3e152;background:#fdfccb}.aside.danger{border-color:#fd9ea7;background:#ffd7d6}Productivity tip:\nLearn how you can quickly insert these loops into your code using JavaScript shortcuts in Visual Studio Code.\n "
<https://notesontech.com/javascript-loops/>