When I printout the javaScript class array, containing several instances from my javascript file, it only shows up on my console, but not on the webpage. How do I get it to show up on the webpage. It has to be done from a separte js file not listed on the same page as the html. This is the code I am using to write out the values in the array. class Item { constructor(name, description, date) { this.name = name; this.description = description; this.date = date; } } const items = []; // Create 7 instances of the Item class items.push(new Item("item1", "description1", "2022-01-01")); items.push(new Item("item2", "description2", "2022-01-02")); items.push(new Item("item3", "description3", "2022-01-03")); items.push(new Item("item4", "description4", "2022-01-04")); items.push(new Item("item5", "description5", "2022-01-05")); items.push(new Item("item6", "description6", "2022-01-06")); items.push(new Item("item7", "description7", "2022-01-07")); // Print out the items in the array for (let i = 0; i < items.length; i++) { console.log(`Name: ${items[i].name}`); console.log(`Description: ${items[i].description}`); console.log(`Date: ${items[i].date}`); console.log("-------------------"); }
When I printout the javaScript class array, containing several instances from my javascript file, it only shows up on my console, but not on the webpage. How do I get it to show up on the webpage. It has to be done from a separte js file not listed on the same page as the html.
This is the code I am using to write out the values in the array.
class Item {
constructor(name, description, date) {
this.name = name;
this.description = description;
this.date = date;
}
}
const items = [];
// Create 7 instances of the Item class
items.push(new Item("item1", "description1", "2022-01-01"));
items.push(new Item("item2", "description2", "2022-01-02"));
items.push(new Item("item3", "description3", "2022-01-03"));
items.push(new Item("item4", "description4", "2022-01-04"));
items.push(new Item("item5", "description5", "2022-01-05"));
items.push(new Item("item6", "description6", "2022-01-06"));
items.push(new Item("item7", "description7", "2022-01-07"));
// Print out the items in the array
for (let i = 0; i < items.length; i++) {
console.log(`Name: ${items[i].name}`);
console.log(`Description: ${items[i].description}`);
console.log(`Date: ${items[i].date}`);
console.log("-------------------");
}
Step by step
Solved in 2 steps