Since there are no dupes, I’ll answer it. There are two things here.
- Replace:
=
- 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;
});
console.log(one);
var two = "";
arr.forEach(function (a) {
two += a;
});
console.log(two);
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.