In this example, I would like to extract 1) the employee number and 2) all his / her tasks. 2) it works, but 1) gives me an object, not a number ...
Do I have to set the employee number as a key / value pair in order to be able to extract the value?
var s = { "schedule": { "employees": { "1000": { "tasks": [ { "task": "task1", "site": "site1", "from": "0900", "to": "1000" }, { "task": "task2", "site": "site2", "from": "0900", "to": "1000" } ] }, "2000": { "tasks": [ { "task": "task3", "site": "site3", "from": "0900", "to": "1000" }, { "task": "task4", "site": "site4", "from": "0900", "to": "1000" } ] } } } } for (var i in s["schedule"]["employees"]) { // this gives me the object, I would like the employee number (eg:1000) console.log(s["schedule"]["employees"][i]); // this gives me the task number for (var j in s["schedule"]["employees"][i].tasks) { console.log(s["schedule"]["employees"][i].tasks[j].task); } }
I do not know why it is difficult for me to understand this. Am I the only one?
source share