With ES6 destructuring, is their any way to destructure nested objects on assignment?
Here is a quick code example to show what I mean:
let node = {
ItemTitle: 'Title',
ItemId: 5,
Menu: {Item: [{ItemId: 579}]
}
// my attempts
let {
ItemId: id,
ItemTitle: title,
Menu['Item']: subItems
} = node
let {
ItemId: id,
ItemTitle: title,
Menu.Item: subItems
} = node
You can just repeat the same syntax for nested levels as with destructuring the top level:
EDIT based on your comment
Pre-edit: Extracting the id of the object within the nested array.
Yes, you can do nested destructuring with ES6. MDN gives you a nice example.