# Array slice \[1:\<variable\]

**URL:** <https://discourse.julialang.org/t/array-slice-1-variable/72567>\
**Category:** New to Julia\
**Tags:** arrays\
**Created:** [December 4, 2021, 8:12am UTC](https://discourse.julialang.org/t/array-slice-1-variable/72567 "2021-12-04T08:12:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![46do14](https://avatars.discourse-cdn.com/v4/letter/4/848f3c/32.png) [@46do14](https://discourse.julialang.org/u/46do14)\
**Post date:** [December 4, 2021, 8:12am UTC](https://discourse.julialang.org/t/array-slice-1-variable/72567/1 "2021-12-04T08:12:33Z")

</div>

Hello

I am new to Julia Language aund I am struggling with following problem:

In my data array are empty elements and I am able to find the indices of these elements

\> indices = findall(x → x == “”, data)

Next I want to slice the array in follwoing way (as an example the very first slice)

\> upto = indices [1] - 1  
\> part = data[1:upto]

an error is reported: MethodError: no method matching getindex(::Symbol,::Int64)

Is it possible to specify a slice by variable(s)

Thanks a lot and best regards

---

<div class="post-metadata">

**Author:** ![hexaeder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hexaeder/32/24403_2.png) [@hexaeder](https://discourse.julialang.org/u/hexaeder)\
**Post date:** [December 4, 2021, 8:32am UTC](https://discourse.julialang.org/t/array-slice-1-variable/72567/2 "2021-12-04T08:32:59Z")

</div>

Hello! I cannot reproduce your error, can you provide a full MWE?

```julia
julia> data = ["foo", "bar", "", "baz", "boo", "", "hoo"];
julia> indices = findall(x -> x == "", data)
2-element Vector{Int64}:
 3
 6
julia> upto = indices[1]-1;
julia> part = data[1:upto]
2-element Vector{String}:
 "foo"
 "bar"

```

However the error indicates, that you’re actually calling `getindex` on a symbol, maybe you overwrote your `data` variable with a symbol at some point?

```julia
julia> data = :foo
:foo

julia> data[1]
ERROR: MethodError: no method matching getindex(::Symbol, ::Int64)
Stacktrace:
 [1] top-level scope
   @ REPL[7]:1

```

Edit: completely wild guess but you might be also interested in

```julia
julia> data = ["foo", "bar", "", "baz", "boo", "", "hoo"];
julia> indices = findall(x -> x == "", data);
julia> deleteat!(data, indices)

```

which will remove all empty strings from your `data` array.

---

<div class="post-metadata">

**Author:** ![46do14](https://avatars.discourse-cdn.com/v4/letter/4/848f3c/32.png) [@46do14](https://discourse.julialang.org/u/46do14)\
**Post date:** [December 4, 2021, 9:46am UTC](https://discourse.julialang.org/t/array-slice-1-variable/72567/3 "2021-12-04T09:46:23Z")

</div>

> [@hexaeder](#):
>
> `part = data[1:upto]`

Hello

thank you for your reply.

Shame on me! You’re abolutely right. It’s works as expected.

Excuse me for the unnecessary noise.

Best regards
