array.shift()
GIVEN calling shift()
on an array
WHEN shifting an empty array THEN undefined
is returned
WHEN shifting an array with one element
THEN the array is empty afterwards
THEN this one element is returned
GIVEN calling shift
on objects other than an array
WHEN calling shift
on an array-like object THEN it works like on an array
WHEN the array is created with a length of 0 THEN the value at index 0 does not get used
WHEN calling shift
on a string THEN this throws, because a string is immutable
Links
Very well readable, easy to understand description of how shift() works.
The version of the specification where `array.shift()` was introduced (PDF 723kB).
Related Katas
Array API
array.sort()
basicsarray.sort()
can take a compare functionarray.shift()
(as introduced in ES3)array.push()
(as introduced in ES3)Array.from()
Array.of()
array.fill()
array.find()
array.findIndex()
array.entries()
array.keys()
array.values()
array.includes()
array.toReversed()
Difficulty Level
BEGINNER
First Published
11 October 2023
Stats
6 tests to solve