Help with Array

Asked

Viewed 36 times

-4

I’m having a problem with javascript. I have an array with 500 positions, I want to print all the data in my html. But when I throw this dice into a div it pulls only the last element. I appreciate your help. Follows code.

<button getList> campos</button>
<textarea id="conteudo"></textarea>



app.getList("FieldList", function(reply){
            var Campos = reply.qFieldList.qItems;
            var texto = document.getElementById('conteudo')

            Campos.forEach((element,index) => {
                texto.innerHTML = element.qName + index

                console.log(element.qName,index)
            })
  • Puts a + after the innerHTML so: +=

1 answer

0


To pull all the elements, just put a + after innerHTML, so that it adds all the elements of the array. The code stays that way:

<button getList> campos</button>
<textarea id="conteudo"></textarea>

app.getList("FieldList", function(reply){
            var Campos = reply.qFieldList.qItems;
            var texto = document.getElementById('conteudo')

            Campos.forEach((element,index) => {
                texto.innerHTML += element.qName + index

                console.log(element.qName,index)
            })
  • It worked, thank you very much

Browser other questions tagged

You are not signed in. Login or sign up in order to post.