@putout/plugin-apply-array-at 
The
at()
method takes an integer value and returns the item at that index, allowing for positive and negative integers. Negative integers count back from the last item in the array.This is not to suggest there is anything wrong with using the square bracket notation. For example
array[0]
would return the first item. However instead of usingarray.length
for latter items; e.g.array[array.length - 1]
for the last item, you can callarray.at(-1)
.(c) MDN
🐊Putout plugin adds ability to apply array.at()
. Renamed to @putout/plugin-apply-at
.
Install
npm i @putout/plugin-apply-array-at
Rule
{
"rules": {
"apply-array-at": "on"
}
}
❌ Example of incorrect code
const latest = (a) => a[a.length - 1];
✅ Example of correct code
const latest = (a) => a.at(-1);
License
MIT