iterating through JSON object with javascript -
in example, extract 1) employee number , 2) of her/his tasks. 2) works, 1) gives me object not number...
do have set employee number key/value pair able extract 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" } ] } } } } (var in s["schedule"]["employees"]) { // gives me object, employee number (eg:1000) console.log(s["schedule"]["employees"][i]); // gives me task number (var j in s["schedule"]["employees"][i].tasks) { console.log(s["schedule"]["employees"][i].tasks[j].task); } }
i don't know why having trouble understanding this. one?
just use i
view key.
console.log(i);
Comments
Post a Comment