# Finding indices using "setdiff"?

**URL:** https://discourse.julialang.org/t/finding-indices-using-setdiff/26930
**Category:** New to Julia
**Created:** [July 29, 2019, 9:13am UTC](https://discourse.julialang.org/t/finding-indices-using-setdiff/26930 "2019-07-29T09:13:43Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)
#### Post date: [July 29, 2019, 9:13am UTC](https://discourse.julialang.org/t/finding-indices-using-setdiff/26930/1 "2019-07-29T09:13:43Z")

</div>

Hey guys, say I have these two arrays:

```julia
A = ["1" "2" "3" "4"];
B = ["1" "2" "3" "4" "5" "6"];

```

Then I can use “setdiff” to find the elements which they do not have in common as such:

```julia
C = setdiff(B,A)
2-element Array{String,1}:
 "5"
 "6"

```

My question is then, would it be possible to get the indices instead? Note the example is string based.

Kind regards

---

<div class="post-metadata">

### Author: ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)
#### Post date: [July 29, 2019, 9:23am UTC](https://discourse.julialang.org/t/finding-indices-using-setdiff/26930/2 "2019-07-29T09:23:32Z")

</div>

One obvious way would be

```julia
[findfirst(isequal(x), B) for x in setdiff(B,A)]

```

By the way, do you deliberately work with `1xN` matrices instead of column vectors (`A = ["1", "2", "3", "4"];`) ? Typically, the latter is preferable.

---

<div class="post-metadata">

### Author: ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)
#### Post date: [July 29, 2019, 9:25am UTC](https://discourse.julialang.org/t/finding-indices-using-setdiff/26930/3 "2019-07-29T09:25:24Z")

</div>

Thanks! It was just an example, usually I also work with column vectors.

Kind regards
