![]() |
VOOZH | about |
The Array.shift() method is an inbuilt TypeScript function used to remove the first element from an array and return that element. This operation modifies the original array by removing the first element.
array.shift(); Parameter: This method does not accept any parameter.
Return Value: This method returns the removed single value of the array.
The below example illustrates the Array shift() method in TypeScriptJS:
In this example The shift() method removes and returns the first element (11) from the numbers array.
Output:
11
[ 89, 23, 7, 98 ]
In this example The shift() method removes and returns the first two elements (2 and 5) from queue.
Output:
2
5
[ 6, 3, 8, 9 ]