0

How can I in ES6 , elegantly and with simple syntax, create a new object from the existing object which has only subset of its properties ?

I currently use object destructuring but I don't like the duplicity here.

  const obj = {a:1, b:2, c:3, d:4, e:5}
  // Create copy which has only a, b and c
  const {a, b, c} = obj
  const newObj = {a, b, c}

Is there a syntax in which I would need to specify the names of properties only once ?

ps-aux
  • 11,627
  • 25
  • 81
  • 128
  • Have a look at this: `object.asssign` https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign – StudioTime Feb 18 '17 at 10:58
  • Can you expand on this a little - it's a bit vague `create a new object from the existing object which has only subset of its properties` - which subset? You have an example? – StudioTime Feb 18 '17 at 11:10
  • Can't you just filter object by key? – peresleguine Feb 18 '17 at 11:17

0 Answers0