How to get a subset of a javascript object's properties -
say have object:
elmo = { color: 'red', annoying: true, height: 'unknown', meta: { one: '1', two: '2'} };
i want make new object subset of properties.
// pseudo code subset = elmo.slice('color', 'height') //=> { color: 'red', height: 'unknown' }
how may achieve this?
using object destructuring , property shorthand
const object = { a: 5, b: 6, c: 7 }; const picked = (({ a, c }) => ({ a, c }))(object); console.log(picked); // { a: 5, c: 7 }
Comments
Post a Comment