Skip to content

step from one key to the next or reverse and return to beginning and continue. Useful in toggles to switch over a set of options or flick a boolean.

Notifications You must be signed in to change notification settings

leighs-hammer/step-through-array

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

step from one key to the next or reverse and return to beginning and continue. Useful in toggles to switch over a set of options or flick a boolean.

Resources

Stars

Watchers

Forks

Packages

No packages published