JavaScript Glossary: Array .shift() Method

Written by - - Aggregated on Friday February 8, 2019


This method takes out the first element from an array and returns it. The shift method mutates the array during this process, reducing its length.

[1, 2, 3, 4, 5].shift()
// 1

This method when called:



No Parameters

Returns a string

The method will return the element removed from the array. If the array is empty, it returns undefined.

const names = ['Johnny', 'Pete', 'Sammy']
// output: 'Johnny'

Common Usage and Snippets

Removing the index element from an array.

« Tips for Using Laravel’s Scheduler - Laravel News - JavaScript Glossary: Array .reverse() … »