How to get last array element in javascript
TIL (Today I Learned) that in JavaScript, there's a cool way to grab the last element of an array using the
at
method. Instead of the traditionalconst lastMember = members[members.length - 1]
which can sometimes feel clunky, now I can simply use
const lastMember = members.at(-1)
It's a nifty trick that makes code cleaner and more concise. Gotta love those little efficiency boosts in programming!
Discover More Reads
Categories: