# Obtain multiple components from a ComponentArray

**URL:** https://discourse.julialang.org/t/obtain-multiple-components-from-a-componentarray/62315
**Category:** General Usage
**Tags:** componentarrays
**Created:** [June 3, 2021, 3:08am UTC](https://discourse.julialang.org/t/obtain-multiple-components-from-a-componentarray/62315 "2021-06-03T03:08:12Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![amrods](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/amrods/32/2543_2.png) [@amrods](https://discourse.julialang.org/u/amrods)
#### Post date: [June 3, 2021, 3:08am UTC](https://discourse.julialang.org/t/obtain-multiple-components-from-a-componentarray/62315/1 "2021-06-03T03:08:12Z")

</div>

Is there a way to obtain multiple components from a `ComponentArray`?  
something like

```julia
using ComponentArrays

ca = ComponentArray(x1 = [1, 2], x2 = [10, 20], x3 = [100, 200])

ca[:x1, :x3]
# would return (ca.x1, ca.x2)

```

---

<div class="post-metadata">

### Author: ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)
#### Post date: [June 3, 2021, 3:25am UTC](https://discourse.julialang.org/t/obtain-multiple-components-from-a-componentarray/62315/2 "2021-06-03T03:25:39Z")

</div>

> [@amrods](#):
>
> ```julia
> using ComponentArrays
> 
> ca = ComponentArray(x1 = [1, 2], x2 = [10, 20], x3 = [100, 200])
> 
> ca[:x1, :x3]
> 
> ```

You can do

```julia
julia> getindex.(Ref(ca), (:x1, :x3))
([1, 2], [100, 200])

```

---

<div class="post-metadata">

### Author: ![jonniedie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonniedie/32/12842_2.png) [@jonniedie](https://discourse.julialang.org/u/jonniedie)
#### Post date: [June 3, 2021, 3:58am UTC](https://discourse.julialang.org/t/obtain-multiple-components-from-a-componentarray/62315/3 "2021-06-03T03:58:22Z")

</div>

It is in work, but it’s a somewhat tough problem for reasons I mention [here](https://github.com/jonniedie/ComponentArrays.jl/issues/71). Until I get it figured out, broadcasting `getproperty` or `getindex` like @dpsanders did is the way to go.
