Instead of using array.length-1 to get the largest index of an array can you do some thing like this array.largestIndex?
Asked
Active
Viewed 278 times
0
Jack Bashford
- 43,180
- 11
- 50
- 79
natnael belay
- 11
- 1
1 Answers
-1
You can use JS getter to do this.
Object.defineProperty(Array.prototype, 'largestIndex', {
get: function () {
return (this.length == 0) ? null : this.length - 1
}
});
natnael belay
- 11
- 1