Lodash: Omit nested properties

Created on 27 Aug 2015  路  3Comments  路  Source: lodash/lodash

Sorry if am posting in the wrong place.

I am looking for a variant of omit function that support nested properties. Example:

var obj = {a:{b:{c:1,d:2}};
var res = _.omit(obj, 'a.b.d'); // res = {a:{b:{c:1}}

Does it already exist? If not, how complicated is it to implement?

Thanks.

question

Most helpful comment

In lodash v4+ we have an _.unset method which is similar to objectPath.del.

For an immutable flavor of unset you can use the fp modules as
require('lodash/fp').unset or require('lodash/fp/unset')

All 3 comments

This doesn't exist in lodash. It would be similar to a merge but with a list of properties to skip. At the moment we don't have a way, even with the customizer, to skip a property assignment.

I'll keep an eye on demand for this feature in the future.

In lodash v4+ we have an _.unset method which is similar to objectPath.del.

For an immutable flavor of unset you can use the fp modules as
require('lodash/fp').unset or require('lodash/fp/unset')

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

toranb picture toranb  路  3Comments

ryyppy picture ryyppy  路  3Comments

rtheunissen picture rtheunissen  路  3Comments

bryandowning picture bryandowning  路  3Comments

aj0strow picture aj0strow  路  3Comments