跳至主要內容

获取 Array 的最后一项

小于 1 分钟featurees-proposal

获取 Array 的最后一项open in new window

模块

类型

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

入口点

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

示例

示例open 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]