Skip to content

Instantly share code, notes, and snippets.

@DavidWells
Created May 12, 2020 18:15
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 DavidWells/b7f1c56dded46044bfc7338f292e929c to your computer and use it in GitHub Desktop.
Save DavidWells/b7f1c56dded46044bfc7338f292e929c to your computer and use it in GitHub Desktop.
rescursively lowercase an object values
function recursiveLowerCase(object) {
if (Array.isArray(object)) {
return object.map((value) => recursiveLowerCase(value))
}
if (object !== null && object.constructor === Object) {
return Object.keys(object).reduce((result, key) => (
Object.assign(Object.assign({}, result), {
[key]: recursiveLowerCase(object[key].toLowerCase())
})
), {})
}
return object
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment