circular-at
v1.0.4
Published
Access array items at any positive or negative index. If the index is out of bounds, it will be wrapped around the length of the array.
Downloads
28,314
Maintainers
Readme
circular-at
Access array items at any positive or negative index. If the index is out of bounds, it will be wrapped around the length of the array.
For example:
import at from 'circular-at'
const array = ['a', 'b', 'c']
at(array, 0) === 'a'
at(array, 1) === 'b'
at(array, 2) === 'c'
at(array, 3) === 'a'
at(array, 4) === 'b'
at(array, 5) === 'c'
// ... and so onThis goes for negative indices as well:
at(array, -1) === 'c'
at(array, -2) === 'b'
at(array, -3) === 'a'
at(array, -4) === 'c'
at(array, -5) === 'b'
// ... and so onIf the given value is not an array, it behaves like value[index]
Install
npm install circular-atLicense
MIT
