# Array of Structs: getindex, slicing, and broadcasting getfield

**URL:** <https://discourse.julialang.org/t/array-of-structs-getindex-slicing-and-broadcasting-getfield/21887>\
**Category:** General Usage\
**Tags:** question\
**Created:** [March 14, 2019, 8:50pm UTC](https://discourse.julialang.org/t/array-of-structs-getindex-slicing-and-broadcasting-getfield/21887 "2019-03-14T20:50:37Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [March 14, 2019, 9:16pm UTC](https://discourse.julialang.org/t/array-of-structs-getindex-slicing-and-broadcasting-getfield/21887/3 "2019-03-14T21:16:18Z")

</div>

I would suggest defining an accessor function and then broadcasting that function:

```julia
id(s::State) = s.ID

id.(states)

```

Does that work for your use case?

---

_[View the full topic](https://discourse.julialang.org/t/array-of-structs-getindex-slicing-and-broadcasting-getfield/21887)._
