VOOZH about

URL: https://www.geeksforgeeks.org/typescript/typescript-array-pop-method/

⇱ TypeScript Array pop() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

TypeScript Array pop() Method

Last Updated : 4 Sep, 2024

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:

98

Example 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
Comment
Article Tags:
Article Tags:

Explore