array-cycle
Simple wrapper utility to navigate and cycle an array
Install
npm i array-cycle
API
constructor(array)
const Cycle = require('array-cycle')
var cycle = new Cycle(['a', 'b', 'c', 'd'])
var cycle = Cycle(['a', 'b', 'c', 'd'])
index
Getter/setter to navigate the array. Loop if out of range
var cycle = Cycle(['a', 'b', 'c', 'd'])
cycle.index
cycle.index = 1
cycle.index
cycle.index -= 2
cycle.index
keys
Getter. Return an object containing the current, next and previous indexes
var cycle = Cycle(['a', 'b', 'c', 'd'])
cycle.keys
values
Getter. Return an object containing the current, next and previous values
var cycle = Cycle(['a', 'b', 'c', 'd'])
cycle.values
last
Getter. Return an object containing the index and value of the last item
var cycle = Cycle(['a', 'b', 'c', 'd'])
cycle.values
Example
const Cycle = require('array-cycle')
var cycle = Cycle(['a', 'b', 'c', 'd'])
cycle.index
cycle.keys
cycle.values
cycle.last
cycle.index++
cycle.index
cycle.keys
cycle.index += 3
cycle.keys
License
MIT