JSFiddle - React, Tailwind, and code Playground
HTML
<div id= "div1">
</div>
<br>
<div id= "div2">
</div>
<br>
<div id= "div3">
</div>
<div id= "div4">
</div>
JavaScript
//this is what a JSON object looks like
var example1 = {"house": {"desk": {"drawer": "pencil"}}};
//to access the pencil in the drawer, treat each property as a method
document.getElementById("div1").textContent = "Inside the drawer is a " + example1.house.desk.drawer;
//what if there are multiple items inside the drawer?
var example2 = {"house": {"desk": {"drawer": ["pencil", "eraser", "notebook", "calculator"]}}};
//i need a notebook, it is in array position 2 (remember, arrays start at index 0)
document.getElementById("div2").textContent = "I need a " + example2.house.desk.drawer[2];
//but i can't live in a house with only a desk, how boring!
var example3 = {"house": [{"desk": {"drawer": ["pencil", "eraser", "notebook", "calculator"]}}, "tv", "waterslide", "stairs"]}
//I want to take my eraser down the waterslide
document.getElementById("div3").textContent = "I want to take my " + example3.house[0].desk.drawer[1];
document.getElementById("div4").textContent = "and I want to go down my " + example3.house[2];