Something like that, than marshal to json

package main

import "fmt"

var StringsArray = []string{"Person1", "Person2", "Person3",
                            "Person4", "Person1", "Person2"}

type MyStruct struct {
    Name string
    Count int
}

func main() {
    mySlice := []MyStruct{}

    for i, name := range StringsArray {
        fmt.Println(name, i)
        mySlice = append(
            mySlice,
            MyStruct{
                Name: name,
                Count: i,
            })
        
    }
    fmt.Println(mySlice)
}

you can try it here - go playground

Answer from d1nch8g on Stack Overflow
🌐
Go by Example
gobyexample.com › range
Go by Example: Range
range iterates over elements in a variety of data structures. Let’s see how to use range with some of the data structures we’ve already learned · Here we use range to sum the numbers in a slice. Arrays work like this too
Discussions

go - Creating an Array of Objects in Range Loop Golang - Stack Overflow
I am a newbie in Golang and trying out things. I have two requirements, Print the Number of Occurrences of the Values in an Array - This is done. Creating a Key-Value of the Key and the Value in an Array - Still working on it. Let me share, what I have I done till now. I have array of Strings · var StringsArray :=["Person1","Person2","Person3","Person4","Person1","Person2"] ... for _, name := range ... More on stackoverflow.com
🌐 stackoverflow.com
I thought I understood how iteration over an array works but apparently not in Golang
The vast majority of Go code uses slices rather than arrays, which already contain a pointer to the backing data and so do not behave the same way as arrays. More on reddit.com
🌐 r/golang
39
34
August 17, 2023
pointers - Range references instead values - Stack Overflow
I saw that range returns the key and the "copy" of the value. Is there a way for that range to return the address of the item? Example package main import "fmt" type MyType st... More on stackoverflow.com
🌐 stackoverflow.com
loops - Is there a way to iterate over a range of integers? - Stack Overflow
If you want to just iterate over a range w/o using and indices or anything else, this code sample worked just fine for me. No extra declaration needed, no _. Haven't checked the performance, though. ... P.S. The very first day in GoLang. More on stackoverflow.com
🌐 stackoverflow.com
March 27, 2016
🌐
YourBasic
yourbasic.org › golang › for-loop-range-array-slice-map-channel
4 basic range loop (for-each) patterns · YourBasic Go
yourbasic.org/golang · Basic for-each loop (slice or array) String iteration: runes or bytes · Map iteration: keys and values · Channel iteration · Gotchas · a := []string{"Foo", "Bar"} for i, s := range a { fmt.Println(i, s) } 0 Foo 1 Bar · The range expression, a, is evaluated once before beginning the loop.
🌐
VictoriaMetrics
victoriametrics.com › blog › how go arrays work and get tricky with for-range
How Go Arrays Work and Get Tricky with For-Range
August 2, 2024 - That means it works like a pass-by-value case. If our array is much bigger than just several elements, making a copy like this will be inefficient and the Go team has optimized this for us by allowing for-range with a pointer to the array.
🌐
Programiz
programiz.com › golang › range
Go range (With Examples)
We can use the for range loop to access the individual index and element of an array. For example,
🌐
GeeksforGeeks
geeksforgeeks.org › go language › range-keyword-in-golang
Range Keyword in Golang - GeeksforGeeks
July 12, 2025 - The range keyword is mainly used in for loops in order to iterate over all the elements of a map, slice, channel, or an array. When it iterates over the elements of an array and slices then it returns the index of the element in an integer form.
Find elsewhere
🌐
Go
go.dev › wiki › Range
Go Wiki: Range Clauses - The Go Programming Language
A range clause provides a way to iterate over an array, slice, string, map, or channel. for k, v := range myMap { log.Printf("key=%v, value=%v", k, v) } for v := range myChannel { log.Printf("value=%v", v) } for i, v := range myArray { log.Printf("array value at [%d]=%v", i, v) }
🌐
Reddit
reddit.com › r/golang › i thought i understood how iteration over an array works but apparently not in golang
r/golang on Reddit: I thought I understood how iteration over an array works but apparently not in Golang
August 17, 2023 - There’s no reason for range <array> to copy the array (from the benchmark even small arrays are worse than slices), it should just implicitly create a slice.
🌐
Medium
medium.com › @ddwen › handling-large-arrays-in-golang-should-you-use-for-range-or-for-loop-9995a02fd316
Handling Large Arrays in Golang: Should You Use For Range or For Loop? | by Dwen | Medium
May 2, 2022 - But in order to facilitate Go developers to iterate on composite data types, such as arrays, slices, channels, and maps, Go provides a variant for range loop, which can even traverse maps and channels.
🌐
Mingrammer
mingrammer.com › gobyexample › range
Go by Example: Range 문
range는 다양한 데이터 구조의 요소들을 순회합니다. 우리가 이미 배운 몇 가지 데이터 구조와 함께 range를 사용하는 방법을 살펴봅시다 · 다음 예시는 슬라이스에 있는 숫자들을 더하기 위해 range를 사용합니다.
🌐
Mgleon08
mgleon08.github.io › blog › 2018 › 05 › 05 › golang-array-range-slices-maps
Golang - Array, Range, Slices, Maps - Leon's Blogging
May 5, 2018 - 陣列 Array Range (each) Slices Maps Variadic Functions 陣列 Array Array 的長度是其類型的一部分,因此陣列不能改變大小。 當定義為 int Array,之後就只能放 int,不能放其他 type int default 值是 0, …
🌐
AstroDeck
xspdf.com › resolution › 50194954.html
xspdf — PDF Generation & Processing API for Developers | xspdf
Powerful PDF API for developers. Generate, convert, merge, split, compress, protect and extract PDFs programmatically. RESTful API with simple integration.