# Manipulating fields of a StructArray does not work

**URL:** <https://discourse.julialang.org/t/manipulating-fields-of-a-structarray-does-not-work/18141>\
**Category:** General Usage\
**Tags:** data\_structures\
**Created:** [November 29, 2018, 2:25pm UTC](https://discourse.julialang.org/t/manipulating-fields-of-a-structarray-does-not-work/18141 "2018-11-29T14:25:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mariok90](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mariok90/32/7076_2.png) [@mariok90](https://discourse.julialang.org/u/mariok90)\
**Post date:** [November 29, 2018, 2:25pm UTC](https://discourse.julialang.org/t/manipulating-fields-of-a-structarray-does-not-work/18141/1 "2018-11-29T14:25:48Z")

</div>

I create a StructArray and want to manipulate the field value of one element.

```julia
julia> using StructArrays
julia> mutable struct Test
           a
           b
         end

julia> arr = [Test(1,1), Test(2,2)]
2-element Array{Test,1}:
 Test(1, 1)
 Test(2, 2)

julia>

julia> sarr = StructArray(arr)
2-element StructArray{Test,1,NamedTuple{(:a, :b),Tuple{Array{Any,1},Array{Any,1}}}}:
 Test(1, 1)
 Test(2, 2)

julia>

julia> sarr[1].a = 5
5

julia>

julia> sarr.a
2-element Array{Any,1}:
 1
 2

```

Why does this not work?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [November 29, 2018, 2:51pm UTC](https://discourse.julialang.org/t/manipulating-fields-of-a-structarray-does-not-work/18141/2 "2018-11-29T14:51:50Z")

</div>

`sarr[1].a` creates a new instance of `Test` by collecting the fields in the different arrays. You want to do:

```julia
julia> sarr.a[1] = 5
5

julia> sarr.a
2-element Array{Any,1}:
 5
 2

```

Also, if you are interested in performance, `StructArray` works much better with immutable (`isbitstype`) structs.
