Contents

Roo

Array.shift!()

Used to remove elements from the beginning of the array thereby “shifting” the remaining elements down in their index.

array.shift!() as Object
array.shift!(n as Number) as Array

Parameters

  • n. Optional integer Number. If specified then this is the number of elements from the beginning of the array to remove

If no parameter is specified then the first element of the array is removed.

Returns

  • If no parameter is passed then it removes the first element from this array and returns the removed element
  • If the optional n parameter is specified then we return an Array of the first n elements, removing the returned elements from this array. This is identical to array.slice!(0, n)

Examples

var args = ["-m", "-q", "filename"]
args.shift!() # => returns "-m"
print(args) # => ["-q", "filename"]

args = ["-m", "-q", "filename"]
args.shift!(2) # => returns ["-m", "-q"]
print(args) # => ["filename"]