# Append an array inside a function

**URL:** <https://discourse.julialang.org/t/append-an-array-inside-a-function/49289>\
**Category:** General Usage\
**Created:** [October 30, 2020, 7:19am UTC](https://discourse.julialang.org/t/append-an-array-inside-a-function/49289 "2020-10-30T07:19:59Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [October 30, 2020, 8:39am UTC](https://discourse.julialang.org/t/append-an-array-inside-a-function/49289/6 "2020-10-30T08:39:40Z")

</div>

No it has appened 5 4s:

```julia
julia> SV = rand(10);

julia> function add_star(SV)
           for i = 1:5
               append!(SV, 4)
           end
           return SV
       end
add_star (generic function with 1 method)

julia> add_star(SV);

julia> SV
15-element Array{Float64,1}:
 0.7833650176317701
 0.5668846033320463
 0.4391438535780501
 0.1708544616711889
 0.5183882750256887
 0.039540666370839306
 0.9220275850039967
 0.2936365813778392
 0.6266212769148911
 0.7356570139131633
 4.0
 4.0
 4.0
 4.0
 4.0

```

Note though, for single element additions you should use `push!` instead of `append!`.

---

_[View the full topic](https://discourse.julialang.org/t/append-an-array-inside-a-function/49289)._
