K
K
Kusmich2015-10-29 01:48:51
css
Kusmich, 2015-10-29 01:48:51

How to insert elements from an array into html tags?

There are elements in the array [1, 2, 3]. And there are tags. How to make the elements from the array inserted into these tags.
The entry needs to look like:<h1> 1 </h1> <h1>2 </h1> <h1>3 </h1>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Inchin ☢, 2015-10-29
@Kusmich

var arr = [1, 2, 3];

var toHTML = "<h1>" + arr.join(" </h1><h1>") + "</h1>";

alert(toHTML);

Or maybe prettier like this:
arr.map(function(h){
   return "<h1>" + h + " </h1>";
}).join("");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question