Skip to content

Instantly share code, notes, and snippets.

@andrhamm
andrhamm / deepChangeKeyCase.js
Last active November 2, 2020 16:20
Javascript Deep Change Key Case
// deeply changes the case of object keys, including in sub arrays of objects
const _ = require('lodash');
function deepChangeKeyCase(value, fn) {
if (Array.isArray(value)) {
return value.map(v => deepChangeKeyCase(v, fn));
} else if (_.isPlainObject(value)) {
return Object.entries(value).reduce((acc, [k, v]) => {
acc[fn(k)] = deepChangeKeyCase(v, fn);
return acc;