Advance to the next item in the array looping when hitting the end.
Last updated 7 years ago by henrikjoreteg .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install array-next 
SYNC missed versions from official npm registry.


Super tiny module that returns the next item in an array when given an item in the array.

If you give it the last item in the array and call next it will loop around and give you the first.


npm install array-next

how to use

var next = require('array-next');

// our demo array
var arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g'];

// if none specified next should return first
next(arr); // returns 'a'

// when given an item in the array it returns the next one
next(arr, 'a'); // returns 'b'

// it also loops if you give it the last item
next(arr, 'c'); // returns 'a'


If you like this, follow @HenrikJoreteg on twitter.

Check out similar resources at:

And check out my book:

unit tests?

run them with npm test

read them here: test.js



Current Tags

  • 0.0.1                                ...           latest (7 years ago)

1 Versions

  • 0.0.1                                ...           7 years ago
Maintainers (1)
Today 2
This Week 3
This Month 31
Last Day 1
Last Week 12
Last Month 39
Dependencies (0)
Dev Dependencies (0)
Dependents (2)

Copyright 2014 - 2017 © |