Skip to main content

Getting last item from Array

Less than 1 minutefeaturees-proposal

Getting last item from Arrayopen in new window

Modules

Types

interface Array<T> {
  get lastItem(): T;
  set lastItem(value: T);
  get lastIndex(): number;
}

Entry points

core-js/proposals/array-last
core-js/full/array/last-item
core-js/full/array/last-index

Example

Exampleopen in new window:

[1, 2, 3].lastItem; // => 3
[1, 2, 3].lastIndex; // => 2

const array = [1, 2, 3];
array.lastItem = 4;

array; // => [1, 2, 4]