step-through-array

0.0.1 • Public • Published

Step through array

Build Status codecov Known Vulnerabilities

simple function that returns the next, or previous array value based on the passed in value. It will return to the begining when it hits the end of the array.

Usage

Standard forwards and backwards

	import stepThroughArray from 'step-through-array' 

		or common JS require

	const stepThroughArray = require('step-through-array' )

	let current = 'tigers'
	const array = ['tigers', 'bears', 'lions']
	const reverse = false // optional passing true will step backwards

	current = stepThroughArray(current, array, reverse)

	// current === 'bears'

	current = stepThroughArray(current, array, reverse)
	// current === 'lions'


Looping

If the next value is undefined it will return to the beginning or the end respectively.

Dependencies (0)

    Dev Dependencies (12)

    Package Sidebar

    Install

    npm i step-through-array

    Weekly Downloads

    1

    Version

    0.0.1

    License

    MIT

    Unpacked Size

    16.8 kB

    Total Files

    11

    Last publish

    Collaborators

    • leighbarnes