2.1.2 β€’ Published 1 year ago

@putout/plugin-apply-array-at v2.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@putout/plugin-apply-array-at NPM version

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 using array.length for latter items; e.g. array[array.length - 1] for the last item, you can call array.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