1

I have an object with multiple properties like so

const someObject = {
  id: 'someid',
  name: 'somename',
  age: 'somenumber',
  someproperty: 'xxx',
  anotherproperty: 'yyy',
  foo: 'bar',
  // ... with many more object properties
}

I have a selector function, with someObject being the input argument, which returns only a few properties of this object.

const functionName = ({id, age, name, foo}) => ({id, age, name, foo});

Is it possible to return destructed argument directly, without the need of repetetive code?

Destructing with ...rest (and then returning rest) is probably bad option since I have way more object properties that I do not want to return than properties that I need.

Toesmash
  • 307
  • 4
  • 20
  • Well you can exclude `const functionName = ({someproperty, anotherproperty, ...whatYouWant}) => whatYouWant` still not the best – epascarello Sep 10 '19 at 13:48

0 Answers0