# Truncate an array

**URL:** <https://www.ruby-forum.com/t/truncate-an-array/100001>\
**Category:** Ruby\
**Created:** [July 26, 2006, 4:34pm UTC](https://www.ruby-forum.com/t/truncate-an-array/100001 "2006-07-26T16:34:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aleks\_Kissinger](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@Aleks\_Kissinger](https://www.ruby-forum.com/u/Aleks_Kissinger)\
**Post date:** [July 26, 2006, 4:34pm UTC](https://www.ruby-forum.com/t/truncate-an-array/100001/1 "2006-07-26T16:34:54Z")

</div>

Is there a generally preferred way to truncate an array? I’ve used  
these two, but is there a better way?

SOME\_ARRAY = [1, 2, 3]

1. SOME\_ARRAY.each\_index{|i| SOME\_ARRAY[i].nil}.compact!
2. SOME\_ARRAY.slice!(1…0)

=\> SOME\_ARRAY == []
