Explain Line of Code (You can loop through object properties by using the for-in loop) [closed]

0
document.getElementById("demo").innerHTML += myObj[x] + "<br>";
    
asked by anonymous 11.01.2017 / 11:31

1 answer

5

As you've seen in the previous question,

 document.getElementById("demo")

serves to retrieve an element defined by id="demo" from the DOM (the structure of the page, assembled according to the HTML).

Then

.innerHTML

retrieve a reference to the HTML that is inside this element. Then

+= 

means "add at the end" a certain value ( a += b equals a = a + b in almost any language).

What's going to be added to the element is this:

myObj[x] + "<br>";

Since myObj[x] is an array , that is, a collection of items. In this case, the added item will be taken from the variable x .

    
11.01.2017 / 11:45