[proposal] Object.pick

Mikkel Davis mikkeld at gmail.com
Wed Jul 25 21:45:38 UTC 2018

I've seen proposals for syntax additions that give functionality similar to
lodash's "pick" utility. But I think it may be more appropriate to add it
as an Object utility in the same vein of `Object.assign`, `Object.keys`,
`Object.values`. After a quick search, I was surprised to not find an
existing proposal like this. Why would that be?

For me, this isn't just one of those "huh, that's a neat lodash util that
would be nifty to have natively." The codebase I work on most often already
has lodash everywhere, and I have found myself utilizing _.pick frequently,
e.g. mapping or passing down portions of React state or props. I really
think is common enough that it justifies addition to the spec.

const person = {
    first: 'Marie',
    last: 'Curie',
    age: 51,
    address: 'Grenoble, France',

Object.pick(person, ['first', 'age']);  // {first: "Marie", age: 51}

The only other concise way to do this I can think of, using latest ES is
`(({first, age}) => ({first, age}))(person)`, which is quite undesirable,
for a variety of reasons.

Another name that might be nice is `Object.slice`.

Mikkel R. Davis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20180725/a0181901/attachment.html>

More information about the es-discuss mailing list