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;     } }); 

and demo http://jsfiddle.net/nikoshr/fez3eyw8/1/


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -