Object pick/omit S1
- Stage: Stage 1
- Status: Active
- ECMAScript edition: —
- Synchronized: Aug 28, 2026
- 中文译文 · Source repository
This proposal introduces static methods Object.pick and Object.omit to conveniently select or exclude object properties based on key lists or predicate functions, addressing ergonomic gaps in destructuring for dynamic or prototype-included property access. The API accepts an optional array of keys or a predicate, with a thisArg, and returns a new plain object, including handling of Symbol keys and prototype properties.
The README below comes from the upstream repository and may contain outdated stage or status metadata. Use the proposal details above as the current source of truth.
Object.{pick, omit}
ECMAScript Proposal, specs, and reference implementation for
Object.pick,Object.omit.
Authors: @Aleen && Hemanth HM
Champion: @js-choi
This proposal is currently stage 1 of the process.
Motivation
Let us consider a few scenarios from the real world to understand what we are trying to solve in this proposal.
- On
MouseEventwe are interested on'ctrlKey', 'shiftKey', 'altKey', 'metaKey'events only. - We have a
configObjectand we need['dependencies', 'devDependencies', 'peerDependencies']from it. - We have an
optionsBagand we would allow on['shell', 'env', 'extendEnv', 'uid', 'gid']on it. - From a
req.bodywe want to extract['name', 'company', 'email', 'password'] - Checking if a component
shouldReloadby extractingcompareKeysfrompropsand compare it withprevProps. - Say we have a
depsObjectand we need to ignore all@internal/packagesfrom it. - We have
propsfrom which we need to remove[‘_csrf’, ‘_method’] - We need to construct a
newModelDataby removingaction.deletedfrom({ ...state.models, ...action.update }) - Filtering configuration objects when the filter list is given by a
CLIargument.
Well, you see life is all about picking what we want and omiting what we don't!
Would life be easier if the language provided a convenient method to help us during similar scenarios?
Now, one might argue saying we can implement pick and omit as below:
The major challenges we see with the above implementations:
- It is not ergonomic!
- If we opt for the destructuring way it doesn't work at all for
pick, or foromitwith dynamic values. - Destructuring cannot
clonea new object whileObject.pickcan - Destructuring cannot
pickup properties from theprototypewhileObject.pickcan - Destructuring cannot
pickproperties dynamically, whileObject.pickcan - Destructuring cannot
omitsome properties, and we can onlycloneanddeletewithout this proposal
We can read more about such use-cases and challenges from es.discourse below:
- Object.{pick,omit}.
- Object restructuring syntax
- Object Array Pick
- js-pick-notation
- slect multiple object values
With that in mind would it not be easier if we had Object.pick and Object.omit static methods?!
Let us now discuss what the API of such a helpful method would be?
Syntax
Parameters
obj: which object you want to pick or omit.pickedKeys(optional): keys of properties you want to pick from the object. The default value is an empty array.omittedKeys(optional): keys of properties you want to pick from the object. The default value is an empty array.predictedFunction(optional): the function to predicted whether the property should be picked or omitted. The default value is an identity:x => x.currentValue: the current value processed in the object.key: the key of thecurrentValuein the object.object: the objectpickwas called upon.
thisArg(optional): the object used asthisinside the predicted function.
Returns
- Returns a new object, which has picked or omitted properties from the object.
Usage
Visions
-
A syntax sugar in the case of picking:
To extend the motivation of this proposal, there may be some syntax notations as an alternative of picking properties from objects, like the proposal, proposal-slice-notation:
There are two ideas around how to wrap picking keys:
-
square brackets:
-
curly brackets
Currently, there is a disagreement on whether properties with default assignment values should be picked.
Nevertheless, it is just a simple vision, and feel free to discuss.
-
FAQ
-
When it comes to the prototype chain of an object, should the method pick or omit it? (The answer may change)
A: The implementation of
_.pickand_.omitby Lodash has taken care about the chain. To keep the rule, we can pick off properties of prototype, but can't omit them:The same rule applies to
__proto__event if it has been deprecated, because the proposal should be pure enough to not specify a special logic to eliminate deprecated properties:In some opinions, picking off or omitting properties from the prototype chain should make the method more extendable:
-
What is the type of the returned value?
A: All these methods should return plain objects:
-
How to handle
Symbol?A:
Symbolshould just be considered as properties withinSymbolkeys, and they should obey the rules mentioned above: -
If some properties of an object are not accessible like throwing an error, can
Object.pickorObject.omitoperate such an object?A: I suggest throwing the error wrapped by
Object.pickorObject.omit, but it is NOT the final choice:The error stack will look like this:
-
In comparison with proposal-shorthand-improvements, when should we use these two methods?
A: Multiple properties. Assume that we need to ensure an object without any side-effected keys except
key1andkey2: -
Why can't be defined on the
Object.prototypedirectly?A: As
Objectis especially fundamental, and both of them will result in conflicts of properties of any other objects. In shorthand, if defined, any objects inherited fromObjectwithpickoromitdefined in its prototype should break. -
Why not define filtered methods corresponding to two actions:
pickByandomitBylike Lodash?A: It is unnecessary to double two methods, because it can be combined into the argument instead:
Besides, the passing filtered method can be easily reversed with equal meaning, and it means that
omitBycan be easily defined aspickBy's inverse.
Notice: If you have any suggestions or ideas about this proposal? Appreciate your discussions via issues.