Javascript Object – Next and Previous Keys

I often need to perform “next” and “previous” operations on standard JavaScript objects or JSON objects. There is no built-in functionality to do this, so here are some helper functions I’ve created to perform these basic operations:

There is a caveat: The EcmaScript specification doesn’t define an order in which keys are returned in an object — unlike an array. However, all modern browsers (as of Feburary 2014) do return them in the order they are supplied.

Functions with mock data and tests:

See the Pen object keys next and previous by Michael Jasper (@mdjasper) on CodePen.