Initial data:
const a = { id: 42, name: 'a', age: 21, score: { c:1, php: 3, js: 5 }, likes: ['X', 'Y'] };
Imagine now you want to only pick { id, name, age }.
--
Traditional: Redundant props and object name
const b = { id: a.id, name: a.name, age: a.age };
--
Two-lines Destructuring: Pollutes namespace with props as variables names
const { id, name, age } = a;
const b = { id, name, age };
--
One-line Destructuring: Doesn't work, you get all properties of a (with score)
const b = { id, name, age } = a;
--
Object Cherry Pick
const b = a.{ id, name, age };
--
Bonus :
const b = a.{ id, name, age: 22 }; // Force value
const b = a.{ id, name, age ??: 22 }; // Default value ??:
const b = a.{ id, name, age as years }; // Rename
const b = a.{ id, name, ['age'] }; // Dynamic string key
const b = a.{ id, name, [/^age/] }; // Dynamic regexp keys (multiple)
const b = a.{ !id, !name }; // All props except id and name
const b = a.{ !id, !name, age:22 as years }; // Idem + Force value + Rename
const b = a.{ id, name, score.{ c, php } }; // Nested pick (Object)
const b = a.{ id, name, likes.[ 0, 1 ] }; // Nested pick (Array)