x
 
1
<!DOCTYPE html>
2
<title>My Example</title>
3
4
5
<p id="msg"></p>
6
7
<script>
8
  // Set variables
9
  var user = { firstname: "Homer", surname: "Rubble", email: "doh@example.com" };
10
  var output = "";
11
12
  // Do the loop
13
  for (var prop in user) {
14
    output += prop + ": " + user[prop] + "<br>";
15
  }
16
17
  // Output results to the above HTML element
18
  document.getElementById("msg").innerHTML = output;
19
</script>