Loop through an array in JavaScript
Three main options: for (var i = 0; i < xs.length; i++) { console.log(xs[i]); } xs.forEach((x, i) => console.log(x)); for (const x of xs) { console.log(x); } Detailed examples are below. 1. Sequential for loop: Run code snippet Pros Works on every environment You can use break and continue flow control statements Cons Too verbose Imperative Easy to have off-by-one errors (sometimes also … Read more