.last()
proposal for JavaScript
In many languages there is an Enumerable#last method which allows you to return the last element of a sequence/ordered list of elements. Currently, to obtain the last item of an array you have to perform:
let array = [1,2,3,4,5];
const lastItem = array[array.length-1];
Examples of popular languages that already implement this method:
Developers should have a more erganomic, clear method of accessing the last item in aformentioned sequence.
A .last()
method for Array.prototype (TODO: Maybe Collection?).
let someArray = [1,2,3,4,5,6,7,8];
console.log(someArray.last()) //would output 8
Overall this strives to promote readibility and syntactic sugar for dev erganomics.
In an empty, null, or undefined property, it should return undefined
(?)