0

Instead of using array.length-1 to get the largest index of an array can you do some thing like this array.largestIndex?

Jack Bashford
  • 43,180
  • 11
  • 50
  • 79

1 Answers1

-1

You can use JS getter to do this.

Object.defineProperty(Array.prototype, 'largestIndex', {
   get: function () {
      return (this.length == 0) ? null : this.length - 1
   }
});