# Is the way, how to get array of value from the Dict by array of keys?

**URL:** <https://discourse.julialang.org/t/is-the-way-how-to-get-array-of-value-from-the-dict-by-array-of-keys/40436>\
**Category:** General Usage\
**Tags:** dictionary\
**Created:** [May 29, 2020, 7:15pm UTC](https://discourse.julialang.org/t/is-the-way-how-to-get-array-of-value-from-the-dict-by-array-of-keys/40436 "2020-05-29T19:15:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![BMval](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bmval/32/7647_2.png) [@BMval](https://discourse.julialang.org/u/BMval)\
**Post date:** [May 29, 2020, 7:15pm UTC](https://discourse.julialang.org/t/is-the-way-how-to-get-array-of-value-from-the-dict-by-array-of-keys/40436/1 "2020-05-29T19:15:05Z")

</div>

Is the way, how to get an array of values from the Dict by array of keys? the same way as DataFrames works.

For instance.

```julia
a=Dict(1=>"a",2="b",3=>"c")
a[[1,2]] gets ["a","b"]

```

thank you in advance.

---

<div class="post-metadata">

**Author:** ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)\
**Post date:** [May 29, 2020, 7:18pm UTC](https://discourse.julialang.org/t/is-the-way-how-to-get-array-of-value-from-the-dict-by-array-of-keys/40436/2 "2020-05-29T19:18:47Z")

</div>

```julia
D=Dict(:a=>"a",:b=>"b",:c=>"c")
getindex.(Ref(D),[:a,:b])

```

---

<div class="post-metadata">

**Author:** ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)\
**Post date:** [May 30, 2020, 1:34am UTC](https://discourse.julialang.org/t/is-the-way-how-to-get-array-of-value-from-the-dict-by-array-of-keys/40436/3 "2020-05-30T01:34:26Z")

</div>

`map(x->D[x], [1,2])` or `[D[x] for x in [1,2]]` is how I’d do it. If you really want to use the syntax you showed, you could do something like (the following is not tested)

```julia
Base.getindex(d::AbstractDict, inds::Vector) = [d[x] for x in inds]

```

But (1) don’t put that into code that other people might load (eg a package) - it’s type piracy - and (2) I don’t know if that will break something else.
