# Indexing Vectors of Structs

**URL:** https://discourse.julialang.org/t/indexing-vectors-of-structs/87346
**Category:** General Usage
**Created:** [September 16, 2022, 4:39am UTC](https://discourse.julialang.org/t/indexing-vectors-of-structs/87346 "2022-09-16T04:39:15Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Name1](https://avatars.discourse-cdn.com/v4/letter/n/ed655f/32.png) [@Name1](https://discourse.julialang.org/u/Name1)
#### Post date: [September 16, 2022, 4:39am UTC](https://discourse.julialang.org/t/indexing-vectors-of-structs/87346/1 "2022-09-16T04:39:16Z")

</div>

Hi all,

```julia
for ii in myStructArray
        
        ii.parameterOne = lowercase(ii.parameterOne)
        
        ii.parameterTwo = lowercase(ii.parameterTwo)

        print("On loop iteration " + ii)

    end

```

I’m looping through an array of my own custom struct called my MyStruct with the array being called myStructArray. I want to access the numerical value of my FOR loop counter ii based upon it’s position within the array at the FOR loop iteration. Is ii the MyStruct object/struct itself, or is it a numerical value that I can use to reference elements within myStructArray? If it’s the former, can I use ii as if it were a numerical value?

Hope all this make sense. If you need any clarification feel free to ask me.

Thanks.

---

<div class="post-metadata">

### Author: ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)
#### Post date: [September 16, 2022, 4:53am UTC](https://discourse.julialang.org/t/indexing-vectors-of-structs/87346/2 "2022-09-16T04:53:10Z")

</div>

[if you do this  
quote=“Name1, post:1, topic:87346”]  
`for ii in myStructArray`  
[/quote]  
then each `ii` is not an index, but an element of your vector.

If you want the index, you can write

```julia
for ii in eachindex(myStructArray) 

```

which is the preferred way, or alternatively, but less general

```julia
for ii in 1:length(myStructArray) 

```

I suggest the first alternative.

---

<div class="post-metadata">

### Author: ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)
#### Post date: [September 16, 2022, 4:54am UTC](https://discourse.julialang.org/t/indexing-vectors-of-structs/87346/3 "2022-09-16T04:54:11Z")

</div>

If you want both the index and the value, you can do

```julia
for (i, x) in pairs(myStructArray)

```
