# Trim a vector in place

**URL:** <https://discourse.julialang.org/t/trim-a-vector-in-place/117436>\
**Category:** General Usage\
**Tags:** arrays\
**Created:** [July 24, 2024, 6:08pm UTC](https://discourse.julialang.org/t/trim-a-vector-in-place/117436 "2024-07-24T18:08:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nathan\_Boyer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nathan_boyer/32/14825_2.png) [@Nathan\_Boyer](https://discourse.julialang.org/u/Nathan_Boyer)\
**Post date:** [July 24, 2024, 6:08pm UTC](https://discourse.julialang.org/t/trim-a-vector-in-place/117436/1 "2024-07-24T18:08:40Z")

</div>

I am trying to delete the last `n` elements from a vector `v`. Is there a better way?

```julia
for _ in 1:n
    pop!(v)
end

```

`pop!` would not accept a range argument.

I try to avoid assuming anything about the indicies after:

> [@Discussion on "Why I no longer recommend Julia" by Yuri Vishnevsky](https://discourse.julialang.org/t/discussion-on-why-i-no-longer-recommend-julia-by-yuri-vishnevsky/81151):
>
> Hey folks! There was a pretty good critical article written about Julia recently called [“Why I no longer recommend Julia” by Yuri Vishnevsky](https://yuri.is/not-julia/) There is an ongoing discussion about the article that has largely been constructive on Slack. Hoping to capture some of these thoughts here to provide actionable points for the community. Feel free to comment or continue streams of thought here about the article and what actions could be done next. Thanks and remember: this is meant to be a cordial and…

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [July 24, 2024, 6:15pm UTC](https://discourse.julialang.org/t/trim-a-vector-in-place/117436/2 "2024-07-24T18:15:13Z")

</div>

> [@Nathan\_Boyer](#):
>
> I am trying to delete the last `n` elements from a vector `v`. Is there a better way?

`resize!(v, length(v) - n)`

More generally, to delete any sequence of indices, you could use `deleteat!`.
