tc39 / proposal-array-last

A JavaScript TC39 Proposal for getting the last element from an array
311 stars 13 forks source link

lastElement as an alias of lastItem #20

Open futagoza opened 6 years ago

futagoza commented 6 years ago

What about using Array.prototype.lastElement() as an alias of Array.prototype.lastItem()?

The reason I suggest this is because usually when referring to the content of an Array, don't most coders say element instead of item? (If they don't, forget I mentioned this 😝)

ljharb commented 6 years ago

I don't think adding aliases is a good idea; we should pick one term.

dy commented 4 years ago

That also has less value by performance/compactness compared to just a[a.length-1].

ljharb commented 4 years ago

@dy not having to mention a twice is all the value this proposal needs imo (just not for more than one way to spell it)

hax commented 4 years ago

I believe the better solution is a[^1] 😆

Maybe we should consider rework this proposal?

ljharb commented 4 years ago

I'm not convinced syntax is a better solution, or even a sensible one here.

G-Rath commented 4 years ago

They are referred to as elements on MDN, but I'd defer to @ljharb & @hax to what The Standard tends to use out of the two.

However, lastElement actually might be better from the autocomplete perspective: right now both properties match lastI, whereas by using lastElement it becomes just last.

It's a small point given it's one letter, but I feel like since item & element are (relatively, for the sake of this issue at least) synonymous, that could be a nice bikeshed-breaker?