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 210 times
0
Jack Bashford
- 40,575
- 10
- 44
- 74
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