0

With the new ES6 syntax, it's easy to only select some keys of an object and assign their values to variables with the same name. It goes like

let foo = {a: 2, b: 1, c:6};
{a, b} = foo;

which is equivalent to

let a = foo.a, b = foo.b;

It's also easier to create objects from variables, like

let bar = {a, b}

which is equivalent to

x = {a: a, b: b}

Now is there a shorthand to get bar from foo directly? (with bar = {a: foo.a, b: foo.b})

Guig
  • 9,891
  • 7
  • 64
  • 126

0 Answers0