# Access elements in an array that are not contiguous

**URL:** https://discourse.julialang.org/t/access-elements-in-an-array-that-are-not-contiguous/52262
**Category:** General Usage
**Created:** [December 23, 2020, 7:23am UTC](https://discourse.julialang.org/t/access-elements-in-an-array-that-are-not-contiguous/52262 "2020-12-23T07:23:49Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![marouane](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marouane/32/16267_2.png) [@marouane](https://discourse.julialang.org/u/marouane)
#### Post date: [December 23, 2020, 7:23am UTC](https://discourse.julialang.org/t/access-elements-in-an-array-that-are-not-contiguous/52262/1 "2020-12-23T07:23:49Z")

</div>

i have some array like this ` x=[2, 1, 1, 0, 1, 0, 1, 0]` and i want to show only the first two elements and the last two elements of the array but when i do this `x[1:2 & 7:8]` it shows me this :

```julia
4-element Array{Int64,1}:
 2
 1
 1
 1

```

which is not true i don’t know why?

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [December 23, 2020, 7:37am UTC](https://discourse.julialang.org/t/access-elements-in-an-array-that-are-not-contiguous/52262/2 "2020-12-23T07:37:34Z")

</div>

> [@marouane](#):
>
> 1:2 & 7:8

```julia
julia> 1:2 & 7:8
1:2:7

```

this is actually `1:(2&7):8` thus `1:2:7`  
you can’t just do as you feel like and expect Julia to read your mind

* * *

```julia
julia> x = reverse(collect(1:8))
8-element Array{Int64,1}:
 8
 7
 6
 5
 4
 3
 2
 1

julia> x[[1:2;7:8]]
4-element Array{Int64,1}:
 8
 7
 2
 1

```

this may be what you wanted

---

<div class="post-metadata">

### Author: ![marouane](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marouane/32/16267_2.png) [@marouane](https://discourse.julialang.org/u/marouane)
#### Post date: [December 23, 2020, 8:07am UTC](https://discourse.julialang.org/t/access-elements-in-an-array-that-are-not-contiguous/52262/3 "2020-12-23T08:07:30Z")

</div>

yeah that’s exactly the expected output
