How does ES6 deconstruct: deconstruct part of an object's value to another variable?

for example, get a variable a , and this variable a may be an object returned by the server.

a: {
  name: "xiaobe",
  age: 22,
  title: "xxx"
}

I want to assign name and age of a to b (actually want to take out more attributes)

is there any quick and easy way? Now I think of deconstructing it like this:

const { name, age } = a;
b = { name, age }
May.14,2022

Why not?

 const b = {name:a.name,age:a.age}

const a = {name,age} = {name: 10, age: 20}
console.log (a) / / = > {name: 10, age: 20}
console.log (name) / / = > 10
console.log (age) / / = > 20
but name and age are global


b = {. Bpm. A}

Menu