DEV Community

Discussion on: How To Efficiently Get The Last Element Of An Array In JavaScript

Collapse
 
devlopr profile image
Aditya Mishra

How is array[-1] not faster than this?

Collapse
 
djamaile profile image
Djamaile

You can use .at(-1) these days.

Collapse
 
gentritbiba profile image
Gentrit Biba

That does not exist in javascript

Collapse
 
devfranpr profile image
DevFranPR

This obiously must be a joke post, look at the numbers.

Collapse
 
devlopr profile image
Aditya Mishra

Lol took me a while to understand 😹

Thread Thread
 
devfranpr profile image
DevFranPR

Blaze it!

Collapse
 
naziiriah profile image
`Nazir Abubakar

or array[array.length - 1]

Collapse
 
devlopr profile image
Aditya Mishra

Lol 😂😂 i forgot that array[-1] doesn't work, this answer of yours was what I meant but forgot to write the correct syntax