How to Get the Index of an Iteration in a for-of Loop in JavaScript

In JavaScript, a for-of loop is a powerful feature introduced in ES6 that allows you to iterate over an array effortlessly. However, by default, it does not provide a straightforward way to access the index of each iteration. But worry not! In this blog post, I will show you how to easily obtain the index of an iteration using a combination of the destructuring syntax and the entries() method. Let’s dive in!...

Iterating over Pages of a Specific Section in Hugo

In Hugo, there may be instances where you need to iterate over the pages of a specific section. This can be achieved by targeting the markdown files stored within a folder under the content directory, such as content/mysection. The following code snippet demonstrates how you can accomplish this: {{ range (where .Site.Pages "Section" "mysection") }} {{ range .Pages }} {{ .RelPermalink }} - {{ .Title }} {{ end }} {{ end }} By utilizing the range function along with the where function, you can iterate over the pages of the desired section....

SwiftUI: The ForEach View - Simplifying Iteration in SwiftUI

The ForEach view is a powerful tool in SwiftUI that allows us to easily iterate over an array or a range and generate views based on the iteration. It simplifies the process of creating repetitive views, such as lists or grids, by reducing the code required. Let’s start with a basic example. We can use ForEach to generate three Text views that display the numbers from 0 to 2: ForEach(0..<3) { number in Text("\(number)") } In this example, we use the ....