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
  • 40,575
  • 10
  • 44
  • 74

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
   }
});