Skip to content

2619. Array Prototype Last 👍

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
declare global {
  interface Array<T> {
    last(): T | -1;
  }
}

Array.prototype.last = function () {
  return this.length === 0 ? -1 : this[this.length - 1];
};

export {};