How to destruct and save nested values?
const obj = {
foo: {
bar: 'Hi!'
}
};
const { foo: { bar } } = obj;
console.log(bar); // Hi!
console.log(foo); // foo is not defined :(
How to keep foo value?
How to destruct and save nested values?
const obj = {
foo: {
bar: 'Hi!'
}
};
const { foo: { bar } } = obj;
console.log(bar); // Hi!
console.log(foo); // foo is not defined :(
How to keep foo value?
Just take foo
as target, too.
const obj = {
foo: {
bar: 'Hi!'
}
};
const { foo: { bar }, foo } = obj;
console.log(bar); // Hi!
console.log(foo); // foo