Given this JSON object, how does lodash remove the reach value from the objects?
{
total: 350,
SN1: {
reach: 200,
enga
There doesn't seem to be a deep omit, but you could iterate over all the keys in the object, and delete reach from the nested objects, recursively:
function omitDeep(obj) {
_.forIn(obj, function(value, key) {
if (_.isObject(value)) {
omitDeep(value);
} else if (key === 'reach') {
delete obj[key];
}
});
}
var obj = {
total: 350,
SN1: {
reach: 200,
engagementRate: 1.35
},
SN2: {
reach: 150,
engagementRate: 1.19
}
};
function omitDeep(obj) {
_.forIn(obj, function(value, key) {
if (_.isObject(value)) {
omitDeep(value);
} else if (key === 'reach') {
delete obj[key];
}
});
}
omitDeep(obj)
console.log(obj);