# Indexing arrays with symbols

**URL:** https://discourse.julialang.org/t/indexing-arrays-with-symbols/84975
**Category:** New to Julia
**Tags:** indexing, array, dictionary
**Created:** [July 29, 2022, 12:24pm UTC](https://discourse.julialang.org/t/indexing-arrays-with-symbols/84975 "2022-07-29T12:24:15Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Atiyah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/atiyah/32/46462_2.png) [@Atiyah](https://discourse.julialang.org/u/Atiyah)
#### Post date: [July 29, 2022, 12:24pm UTC](https://discourse.julialang.org/t/indexing-arrays-with-symbols/84975/1 "2022-07-29T12:24:15Z")

</div>

I came over [the following thread](https://discourse.julialang.org/t/struct-with-array-and-dict-of-symbols-index-array-by-symbol/9040) and was wondering if there is still an intuitive way to index an array with symbols.

Say if

`> arr = [1,2,3]`

could be still indexed with  
`> arr[:a], arr[:b], arr[:c]`

Background: I want to have a generic function that works both on a function argument that corresponds to an array or a dictionary of symbols.

---

<div class="post-metadata">

### Author: ![StevenWhitaker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevenwhitaker/32/9749_2.png) [@StevenWhitaker](https://discourse.julialang.org/u/StevenWhitaker)
#### Post date: [July 29, 2022, 12:53pm UTC](https://discourse.julialang.org/t/indexing-arrays-with-symbols/84975/2 "2022-07-29T12:53:04Z")

</div>

It depends on what you want to do, but using something like `eachindex` might work.

Or write a method that takes a `Dict` and converts it to an `Array` first and then passes it to your method that takes an `Array`.

If you really want an array that can be indexed with `Symbol`s, you could make your own type that acts like an `Array`, and then add a method to `Base.getindex` for your type that can take `Symbol`s.

---

<div class="post-metadata">

### Author: ![hdavid16](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hdavid16/32/11531_2.png) [@hdavid16](https://discourse.julialang.org/u/hdavid16)
#### Post date: [July 29, 2022, 1:12pm UTC](https://discourse.julialang.org/t/indexing-arrays-with-symbols/84975/3 "2022-07-29T13:12:25Z")

</div>

Use NamedArrays.jl
