how do you use the object key as a header and value child list in javascript?

Since there are no dupes, I’ll answer it. There are two things here.

  1. Replace: =
  2. Append: +=

What you’re doing is replacing. What you need to be doing is appending. Your solution is:

let list = "";
values.forEach(item => {
  list += `<li class="list">${ item }</li>`;

An example snippet to show you what’s happening will be:

var arr = ["One", "Two", "Three"];

var one = "";
arr.forEach(function (a) {
  one = a;

var two = "";
arr.forEach(function (a) {
  two += a;

I hope you understand the cases above with the variables one and two. You’re looking for two but you have implemented one.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top