I´m often using destructor to split an object into parts:
const foo = {
a: "part 1",
b: "part 2",
c: "part 3",
}
//get a,b,c
const ({a,b,c}) = foo;
console.log(a,b,c) // "part 1, part 2, part 3"
I´m also sometimes using destructor to get parts of the objects that are properties:
const foo = {
a: "part 1",
b: "part 2",
c: "part 3",
d: {
a: "part a from d",
b: "part b from d",
c: "part c from d",
}
}
//just get a from d
const ({d: {a}}) = foo; // I split out a here but not d
console.log(a) // "part a from d"
console.log(d) // d is not defined but I want d here
How can I get d
here including a, b and c is it possible in the same line?