Skip to content

Instantly share code, notes, and snippets.

@redgeoff
Last active December 31, 2020 00:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save redgeoff/868196d18356e5b8d4c6c341f7f4a40b to your computer and use it in GitHub Desktop.
Save redgeoff/868196d18356e5b8d4c6c341f7f4a40b to your computer and use it in GitHub Desktop.
eachLeaf - Recursively process each leaf in JavaScript object
import each from 'lodash/each';
const eachLeafInner = (collection, iteratee, key) => {
if (collection && typeof collection === 'object') {
each(collection, (value, key) => {
eachLeafInner(value, iteratee, key);
})
} else if (key !== undefined) {
iteratee(collection, key)
}
}
const eachLeaf = (collection, iteratee) => {
eachLeafInner(collection, iteratee);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment