Search code examples
javascriptnode.jslodash

Copy all but one field with Lodash, without using Object.assign()


If I have an object like so:

const obj  = { A: 1, B: 2, C: 3, D: 4 };

How can I copy all key/values except for C to a new object?

Underscore has the _.pick() functionality, but I am looking to do the opposite.


Solution

  • You can achieve this with the omit method : https://lodash.com/docs/4.17.4#omit