Object destructuring
You can also destructure objects:
let o = { a: "foo", b: 12, c: "bar" } let {a, b} = o;
This creates new variables a
and b
from o.a
and o.b
. Notice that you can skip c
if you don’t need it.
Like array destructuring, you can have assignment without declaration:
({a, b} = {a: "baz", b: 101});
Notice that we had to surround this statement with parentheses. JavaScript normally parses a {
as the start of block.
Please login to continue.