![]() |
VOOZH | about |
The TypeScript Array.pop() method removes the last element from an array and returns it. This operation modifies the original array by reducing its length by one. If the array is empty, pop() returns undefined without making any changes to the array.
Syntax:
array.pop(); Parameter: This method does not accept any parameter.
Return Value: This method returns the removed element from the array.
The below examples illustrate the Array pop() method in TypeScript.
Example 1: In this example The pop() method removes the last element from the arr array, assigning it to val. val can be a number or undefined, and the removed element (98) is printed.
Output:
98Example 2: In this example the pop() method removes and logs the last four elements from the arr array. Each iteration prints the removed element
Output:
9
8
3
6