JSON Objects

Example

<!DOCTYPE html>
<html>
<body>

<p>Access a JSON object using dot notation:</p>

<p id=”demo”></p>

<script>
var myObj, x;
myObj = {“name”:”John”, “age”:30, “car”:null};
x = myObj.name;
document.getElementById(“demo”).innerHTML = x;
</script>

</body>
</html>

Output

Access a JSON object using dot notation:

Example

<!DOCTYPE html>
<html>
<body>

<p>How to loop through all properties in a JSON object.</p>

<p id=”demo”></p>

<script>
var myObj = {“name”:”John”, “age”:30, “car”:null};
for (x in myObj) {
document.getElementById(“demo”).innerHTML += x + “<br>”;
}
</script>

</body>
</html>

 

Output

How to loop through all properties in a JSON object.

Updated: February 13, 2019 — 10:02 am
Java Script © 2019