I have been wondering if there is a way I can destructure this object in the snippet.
Here is what I have tried but it seems not working...
const {
_links: {
self: [{ href: mainMedia }],
},
_links: { "wp:attachment": attachmentMedia:{[{href:attachment}]} },
_links: { "wp:featuredmedia": featuredMedia:{[{href:attachment}] } }
} = data;
The attachmentMedia and featuredMedia are my alias and I am interested in the link each array.
const [{ href: mainMedia }] = data._links["self"];
const attachmentMedia = data._links["wp:attachment"]
.map(({ href: attachment }) => ({ attachment }));
const featuredMedia = data._links["wp:featuredmedia"]
.map(({ href: attachment }) => ({ attachment }));
Is this your expectation?