-1
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?

Univel
  • 21
  • 8
  • Does this answer your question? [How can I access and process nested objects, arrays, or JSON?](https://stackoverflow.com/questions/11922383/how-can-i-access-and-process-nested-objects-arrays-or-json) – jabaa May 26 '23 at 01:51
  • There are multiple objects inside the array. Which one do you want? – Barmar May 26 '23 at 02:09
  • `user.labels[0].id` will get the first one. `user.labels.map(label => label.id)` will get an array of all of them. – Barmar May 26 '23 at 02:09
  • i thinked of using another looping for it but for weird reason I can't think how to use it. That really hit the spot. Thanks alot – Univel May 26 '23 at 02:40
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community May 26 '23 at 04:31

1 Answers1

-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);
Univel
  • 21
  • 8