0
document.getElementById("demo").innerHTML += myObj[x] + "<br>";
5
As you saw in the previous question,
document.getElementById("demo")
to recover from DOM (the page structure, mounted according to HTML) an element defined by id="demo"
.
Then the
.innerHTML
retrieves a reference to the HTML inside this element. Then,
+=
means "add at end" a certain value ( a += b
amounts to a = a + b
in virtually any language).
What will be added to the element is this:
myObj[x] + "<br>";
Whereas myObj[x]
is a array, i.e., a collection of items. In this case, the added item will be taken from the variable x
.
Thank you very much ... And I’m sorry for these somewhat "amateur" questions, but I’m trying to understand my doubts 100% to have a good foundation !
I am already reading ... I thought I was Creating but I was Editing ... To Mutch Coffe .... Excuse me .... I will try to be as clear as possible in the future .
@Bacco I know your answer has already been accepted, but looking at the issue history of the question, there was more important content there. I suppose the OP has chosen to remove the pertinent HTML by not knowing how to format it, which causes the SE engine to delete it.
@Victorstafusa he ended up asking a separate question. He even reversed pq I answered the previous version. His intention was good, but in the end this extra content ended up staying in another better post, so I returned to the state that was..
Browser other questions tagged javascript
You are not signed in. Login or sign up in order to post.
Is concatenating the value of
myObj[x]
the content of the id elementdemo
.– Renan Gomes
I was wrong, I am already going to restructure the previous Question ... I’m sorry, but I was clarified with your Answer !
– ManiacSaw
Already this ! Does not Spoil, because the Answer is already below the Correct Question
– ManiacSaw
@Maniacsaw do so, when opening a question, look for the code as complete as possible, but also explain the parts you understand and the ones you don’t, so we can focus the explanation on the part you’re really struggling with.
– Bacco
ok... I’ll do it in the next few questions
– ManiacSaw
And don’t be afraid to ask, the recommendation is only for a better use of the site. Over time, get the hang of.
– Bacco
... What does the title have to do with the question?
– Genos
Possible duplicate of Javascript Doubt ( Loopin through an array using a for loop )
– Bacco