# Proper way to deal with \`Vector{Any}\` when defining a function

**URL:** <https://discourse.julialang.org/t/proper-way-to-deal-with-vector-any-when-defining-a-function/114422>\
**Category:** General Usage\
**Tags:** question, type, function\
**Created:** [May 18, 2024, 9:00am UTC](https://discourse.julialang.org/t/proper-way-to-deal-with-vector-any-when-defining-a-function/114422 "2024-05-18T09:00:50Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)\
**Post date:** [May 18, 2024, 12:26pm UTC](https://discourse.julialang.org/t/proper-way-to-deal-with-vector-any-when-defining-a-function/114422/3 "2024-05-18T12:26:29Z")

</div>

> [@WuSiren](#):
>
> ```julia
> arr = []
> push!(arr, "hello")
> push!(arr, "world"
> 
> ```

The above is equivalent to the following.

```julia
arr = Any[]
push!(arr, "hello")
push!(arr, "world"

```

To avoid `Vector{Any}` do

```julia
arr = String[]
push!(arr, "hello")
push!(arr, "world"

```

If you cannot avoid it, the do:

```julia
julia> arr = Any[]
Any[]

julia> push!(arr, "hello")
1-element Vector{Any}:
 "hello"

julia> push!(arr, "world")
2-element Vector{Any}:
 "hello"
 "world"

julia> arr = identity.(arr)
2-element Vector{String}:
 "hello"
 "world"

```

---

_[View the full topic](https://discourse.julialang.org/t/proper-way-to-deal-with-vector-any-when-defining-a-function/114422)._
