Imagine I have an object called projects. The projects object has a key called projects that is an array of 2 other objects. Each one of the other 2 objects has an array of images. I was able to iterate through each image in the array of each object using for in loops but I want to use for loops or forEach instead. What can I do? Here is my code:
var projects = {};
projects.projects = [
{
"title": "mycode",
"dates": "mycode",
"description": "mycode",
"images": ["http://lorempixel.com/400/200/", "http://lorempixel.com/350/150/", "http://lorempixel.com/500/300/"]
},
{
"title": "mycode",
"dates": "mycode",
"description": "mycode",
"images": ["http://lorempixel.com/400/200/", "http://lorempixel.com/350/150/", "http://lorempixel.com/500/300/"]
}
];
projects.display = function() {
for (var i = 0; i < projects.projects.length; i++) {
var formattedProjectTitle = HTMLprojectTitle.replace("%data%", projects.projects[i].title);
$(".project-entry:last").append(formattedProjectTitle);
var formattedProjectDates = HTMLprojectDates.replace("%data%", projects.projects[i].dates);
$(".project-entry:last").append(formattedProjectDates);
var formattedProjectDescription = HTMLprojectDescription.replace("%data%", projects.projects[i].description);
$(".project-entry:last").append(formattedProjectDescription);
//Iterate through each image in the projects objects.
for (image in projects.projects[i].images) {
var formattedProjectImages = HTMLprojectImage.replace("%data%", projects.projects[i].images[image]);
$(".project-entry:last").append(formattedProjectImages);
}
}
}