Я пытаюсь выяснить, как зацикливаться на массиве в объекте в массиве и console.log. Я хочу иметь возможность console.log для каждой временной шкалы и изображения в своем собственном теге <p>
и <img>
под соответствующим именем пользователя.
Хотите отобразить следующим образом:
Имя пользователя timeline1 image1
timeline2 image2
ect ..
Вот код, который у меня естьдо сих пор:
{
username: "Bobby",
timeline: ["The weekend is finally here!!!!", "Any one have any plans?"],
image: [
"https://images.unsplash.com/photo-1462887749044-b47cb05b83b8?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80",
"https://images.unsplash.com/photo-1516383074327-ac4841225abf?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80"
]
},
{
username: "Sally",
timeline: "Javascript is so coooool.",
image:
"https://images.unsplash.com/photo-1542653309-dbc6a80a7484?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1051&q=80"
},
{
username: "John",
timeline: "I am so good at Javascript.",
image:
"https://images.unsplash.com/photo-1499209974431-9dddcece7f88?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80"
},
{
username: "Jonathan",
timeline: "Hello everyone, here at school.",
image:
"https://images.unsplash.com/photo-1551754809-c0a4e5b246ec?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80"
},
{
username: "Matthew",
timeline: "Just got back from the doctor.",
image:
"https://images.unsplash.com/photo-1537977193203-d4fce971cb5e?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1044&q=80"
}
];
for (i = 0; i < newsFeed.length; i++) {
output += `
<div class="newsFeedHeader">
<h1>${newsFeed[i].username}'s timeline.</h1>
<p>${newsFeed[i].timeline}</p>
<img src=${newsFeed[i].image} alt='joy image'>
</div>
`;
}