DEV Community

Discussion on: Get last element of array in JavsScript

Collapse
 
lexlohr profile image
Alex Lohr

You can easily polyfill it:

if (![].at) {
  Array.prototype.at = function(pos) { return this.slice(pos, pos + 1)[0] }
}
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
nbouvrette profile image
Nicolas Bouvrette

This won't work with negative values.