I am trying to convert an object to a leaner version using destructuring.
My object includes a nested array which also contains objects, from this array I would only like a few fields.
I can do the nested object destructuring fine, and the array destructuring fine but not together?
My current try looks like this:
var data = {
title: "title1",
bar: "asdf",
innerData: [
{
title: "inner-title1",
foo: "asdf"
},
{
title: "inner-title2",
foo: "asdf"
}
]
};
var { title, innerData: [ { title} ] } = data;
console.log(title);
for (var { title} of innerData) {
console.log(title);
}
But get a message saying innerData is not defined.
The outcome I would like might be:
{
title: "title1",
innerData: [
{
title: "inner-title1"
},
{
title: "inner-title2"
}
]
};