5

The one thing I haven't figured out how to do using new ES syntax is create an object that is a subset of another based on declared included values.

Here's what I'm trying to do:

//input
let user = {
  id: 123,
  foo: 'foo',
  bar: 'bar',
  password: 'hunter2'
};

//output
let safeUser = {
  id: user.id,
  foo: user.foo,
  bar: user.bar
}

//NOT this (I don't want to declare excluded vals)
let {password, ...safeUser} = user; 

If it's not possible, anyone know if something is in the works? I looked on esdiscuss & babel but nothing turned up.

Matt K
  • 4,314
  • 3
  • 19
  • 33

0 Answers0