[英]How to destructure a nested object with special character and using object alias
I have been wondering if there is a way I can destructure this object in the snippet.我一直想知道是否有一种方法可以在片段中解构这个 object。
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. attachmentMedia
和featuredMedia
是我的别名,我对每个数组的链接感兴趣。
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?这是你的期望吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.