Skip to content

TheLarkInn/proposal-dot-last

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

proposal-dot-last

.last() proposal for JavaScript

Motivation and use cases

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.

Proposed Solution

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.

Empty, null, or undefined

In an empty, null, or undefined property, it should return undefined (?)

About

`.last()` proposal for JavaScript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published