英文:
How to extract the array inside the object
问题
const html = test.map((user) => {
return `
<div class="user">
ID: ${user.labels.id}
</div>
`;
document.querySelector("#app").insertAdjacentHTML("afterbegin", html);
API URL: https://api.github.com/repos/vercel/next.js/issues
There's an array inside the object which is labels. And I want to try to extract the object inside "labels" array. But since the method I use only work if it's an object, how to do it if it's an array?
<details>
<summary>英文:</summary>
const html = test.map((user) => {
return
;
<div class="user">
ID: ${user.labels.id}
</div>
document.querySelector("#app").insertAdjacentHTML("afterbegin", html);
API URL : https://api.github.com/repos/vercel/next.js/issues
There's an array inside the object which is labels. And I want to try to extract the object inside "labels" array. But since the method I use only work if it's an object, how to do it if it's an array?
</details>
# 答案1
**得分**: -1
const html =
test.map((user) => {
return `
${user.labels.map((label) => {
return `
<div class="label">
Labels:<br>
ID: ${label.id}<br>
Node ID: ${label.node_id}<br>
</div>
`;
})}
</p>
</div>
`;
})
.join("");
console.log(html);
document.querySelector("#app").insertAdjacentHTML("afterbegin", html);
<details>
<summary>英文:</summary>
const html =
test.map((user) => {
return `
${user.labels.map((label) => {
return `
<div class="label">
Labels:<br>
ID: ${label.id}<br>
Node ID: ${label.node_id}<br>
</div>
`;
})}
</p>
</div>
`;
})
.join("");
console.log(html);
document.querySelector("#app").insertAdjacentHTML("afterbegin", html);
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论