EDIT: Safari does not support it ,_,
But use it in Node js or with a bundler!
So some people would say:
array[array.length-1]
But I'd say:
array.at(-1)
The Performance of both is the same.
MDN article: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at
Top comments (2)
Yes it works in Safari, check the browser compatibility
Array.at
has been "recently" introduced into the core API of JavaScript, the purpose is to get better readability and to facilitate getting Array positions starting from the end:However if you're getting specific positions forwards is not that fancy:
Best regards!
Nice, very cool :)