[javascript] How to get a subset of a javascript object's properties

Using Object Destructuring and Property Shorthand

_x000D_
_x000D_
const object = { a: 5, b: 6, c: 7  };_x000D_
const picked = (({ a, c }) => ({ a, c }))(object);_x000D_
_x000D_
console.log(picked); // { a: 5, c: 7 }
_x000D_
_x000D_
_x000D_


From Philipp Kewisch:

This is really just an anonymous function being called instantly. All of this can be found on the Destructuring Assignment page on MDN. Here is an expanded form

_x000D_
_x000D_
let unwrap = ({a, c}) => ({a, c});_x000D_
_x000D_
let unwrap2 = function({a, c}) { return { a, c }; };_x000D_
_x000D_
let picked = unwrap({ a: 5, b: 6, c: 7 });_x000D_
_x000D_
let picked2 = unwrap2({a: 5, b: 6, c: 7})_x000D_
_x000D_
console.log(picked)_x000D_
console.log(picked2)
_x000D_
_x000D_
_x000D_