Created
May 12, 2020 18:15
-
-
Save DavidWells/b7f1c56dded46044bfc7338f292e929c to your computer and use it in GitHub Desktop.
rescursively lowercase an object values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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