0

I have code returning a list of results from my db (through a loop on front end), but I cannot seem to output a new line for each result that comes back.

    <div id="names">
<% if(data.length){ 
    for(var i = 0;i < data.length;i++) { %>
        <p><%= data[i].FULLNAME %></p>
        <% }
               }else{ %>
            <p>nothing</p>
        <% } %>
    </div>
      <script>
          var listOfNames = document.getElementById("names").innerText
          console.log("list of names: " + listOfNames)
          const words = [listOfNames] //I need to create new line after every name returned

the results basically come out like this:

name1 name2 name1

while I need them to come out like this:

name1
name2
name3

thanks for the help in advance

Gianluca
  • 900
  • 8
  • 27
  • Does this answer your question? [What is the proper way to loop through an array in an EJS template after an AJAX Call (using ExpressJS)?](https://stackoverflow.com/questions/38179077/what-is-the-proper-way-to-loop-through-an-array-in-an-ejs-template-after-an-ajax) – TKoL Dec 21 '20 at 14:56
  • Without html you will get the plain text in one row. Try to change .innerText to .innerHTML – lortschi Dec 21 '20 at 14:59
  • is a Block element. Normally you every p element should be displayed on new line, except in you CSS you make it inline – user1592129 Dec 21 '20 at 15:01

0 Answers0