[英]I have a array of characters, I want to display the name, house and image in rows of 4 in html using javascript. Do I foreach?
tried something like this potterCharacters.forEach((x) => getCharacters(x.name));
试过这样的东西
potterCharacters.forEach((x) => getCharacters(x.name));
This displays the name only but cant seem to go on with it.这仅显示名称,但似乎无法继续。
function Init()
{
debugger;
potterCharacters.forEach((x) => getCharacters(x.name));
text += "</ul>";
document.getElementById("rows").innerHTML = text;
}
function getCharacters(value)
{
text += "<th>" + value + "</th>";
}```
function Init() {
const text = potterCharacters.map(character => {
const { name, house, image } = character
return `<tr>
<td>${name}</td>
<td>${house}</td>
<td><img src="${image}"/></td>
</tr>`
})
document.getElementById("characters").innerHTML = text
}
html: html:
<table id="characters"></table>
tried something like this potterCharacters.forEach((x) => getCharacters(x.name));
尝试过类似
potterCharacters.forEach((x) => getCharacters(x.name));
This displays the name only but cant seem to go on with it.这仅显示名称,但似乎无法继续使用。
function Init()
{
debugger;
potterCharacters.forEach((x) => getCharacters(x.name));
text += "</ul>";
document.getElementById("rows").innerHTML = text;
}
function getCharacters(value)
{
text += "<th>" + value + "</th>";
}```
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.