pop

Summary

Removes the last element of the array.

Usage

public T+ pop()

Returns

The last element of the array that was removed or undefined if there were no elements left in the array.

Description

Removes the last element of the array and returns the element. If there are no elements in the array, undefined is returned.

This method mutates the array.

Examples

Basic Usage
1
2
3
4
5
6
import System;
 
int[] arr = [ 1, 2, 3, 5 ];
Console.log(arr.last()); // 5
arr.pop();               // Removes last element
Console.log(arr.last()); // 3
Return and remove the last element of the array
1
2
3
4
5
6
import System;
 
int[] arr = [ 1, 2, 3, 4, 500, 600, 700, 800 ];
Console.log(arr.length); // 8
Console.log(arr.pop());  // 800
Console.log(arr.length); // 7

Share

HTML | BBCode | Direct Link