let options = {
size: {
width: 100,
height: 200
},
items: ["Cake", "Donut"],
extra: true
};
// destructuring assignment split in multiple lines for clarity
let {
size: { // put size here
width,
height
},
items: [item1, item2], // assign items here
title = "Menu" // not present in the object (default value is used)
} = options;
console.log(title); // Menu
This is working fine, but when I want to get list of data from API it doesn't work with nested destructuring. However, I can show data by using && for example options && options.title
it's worked fine.