javascript - Object: Deep omit -
is there way use _.omit
on nested object properties?
i want happen:
schema = { firstname: { type: string }, secret: { type: string, optional: true, private: true } }; schema = _.nestedomit(schema, 'private'); console.log(schema); // should log // { // firstname: { // type: string // }, // secret: { // type: string, // optional: true // } // }
_.nestedomit
doesn't exist , _.omit
doesn't affect nested properties, should clear i'm looking for.
it doesn't have underscore, in experience makes things shorter , clearer.
you create nestedomit
mixin traverse object remove unwanted key. like
_.mixin({ nestedomit: function(obj, iteratee, context) { // basic _.omit on current object var r = _.omit(obj, iteratee, context); //transform children objects _.each(r, function(val, key) { if (typeof(val) === "object") r[key] = _.nestedomit(val, iteratee, context); }); return r; } });
Comments
Post a Comment