2
We can imagine the following array
:
var arr = ["a", "b", "c", "d"];
I know I can use the join(", ")
to turn it into a type string: "a, b, c, d"
, but I would like to create an element for each item of the array, which is: "<li>a</li> <li>b</li> <li>c</li> <li>d</li>"
, it is possible to do this using the join()
?
Note: I know that I can also loop and do this using other methods, I would just like to reduce code even.
Really needs the
map
?– Wallace Maxters
@Wallacemaxters is not really a matter of necessity - in this example, but it’s simpler for you to work with the separate element. What do you do on
map
will be reflected in all. Think that now you need to put a<a>
within the<li>
.– Woss
You’re right. And depending on the situation, I would even appeal to a
document.createElement
to look more elegant :p– Wallace Maxters