Unshift

Updated: 10/17/2017 by Computer Hope

In some programming languages unshift is a function that adds one or more elements to the beginning of an array. For example, in the Perl code below unshift adds "zero" to the beginning of the array to make it "zero one two three".

my @example = ('one', 'two', 'three');
unshift @example, 'zero';
print "@example\n";        #Prints: zero one two three
Tip

To add to the end of an array, use the push function. To remove the first element of the array, use the shift function.

Programming terms