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?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.