Having Issue on Looping In JSON File
Can you please take a look at
This Demo and let me know why I am not able to load all objects in the JSON file under `utility` into the table
- var data = {
- "utility": {
- "Water": {
- "account": "99999",
- "balance": "5555",
- "owner": "Fred"
- },
-
- "Phone": {
- "account": "7777",
- "balance": "6666",
- "owner": "Mark"
- },
-
- "Power": {
- "account": "A9885",
- "balance": "2222",
- "owner": "Suzan"
- }
- },
-
- "clients": {
- "David": {
- "account": "99999",
- "balance": "5555",
- "Date": "Jan 11"
- },
-
- "George": {
- "account": "7777",
- "balance": "6666",
- "Date": "March 22"
- },
-
- "Marco": {
- "account": "A9885",
- "balance": "2222",
- "Date": "Feb 25"
- }
- }
-
- }
-
-
- for (var p in data.utility) {
- console.log(p);
- $("#tbl-data").append('<tr><td>' + p + '</td><td>' + p.utility.water.account + '</td><td>' + p.utility.water.balance + '</td><td>' + p.utility.water.owner + '</td></tr>');
- }
-
- <div class="container">
- <table id="tbl-data" class="table table-hover"></table>
- <div>
As you can see I am getting this error in the console
Uncaught TypeError: Cannot read property 'water' of undefined
but cant' figure it out why?