I think you are missing one of the methods that was added not too long ago. Array.prototype.at(). To get the last element in an array you can do myArr.at(-1). developer.mozilla.org/en-US/docs/W...
I'm a frontend developer, with a passion for clean and efficient code. I'm using mostly JavaScript, TypeScript, React & CSS. I'm always trying to grow as a developer by learning new technologies.
I think you are missing one of the methods that was added not too long ago.
Array.prototype.at()
. To get the last element in an array you can domyArr.at(-1)
.developer.mozilla.org/en-US/docs/W...
Oh Yes !!! Thank You. This pretty usefull and easy
While it’s a cool new method, keep in mind that currently it’s not supported in Safari based devices.
In Safari Technology Preview you can activate it via
Develop > Experimental Features
You can easily polyfill it:
This won't work with negative values.