There is json.
wt = { "days": [{ "2": [{"1":"1","2":"2","4":"4","6":"6"}], "3": [{"1":"1","3":"3","7":"7"}] }], "time_from_h": [{ "2": [{"1":"8","2":"9","4":"8","6":"10"}], "3": [{"1":"8","3":"9","7":"8"}] }], "time_from_m": [{ "2": [{"1":"0","2":"5","4":"30","6":"50"}], "3": [{"1":"10","3":"0","7":"10"}] }], "time_to_h": [{ "2": [{"1":"21","2":"20","4":"22","6":"20"}], "3": [{"1":"19","3":"17","7":"19"}] }], "time_to_m": [{ "2": [{"1":"30","2":"40","4":"40","6":"30"}], "3": [{"1":"59","3":"10","7":"40"}] }] } How to apply to: wt.days.2.4 (get exactly the value of the item)
How to check if wt.days.2
Those. there will be a function to which id will be passed. So you need to check if in id = 2 in wt.days and if there is, then output wt.days.2.4
var i = 2; console.log(wt.days[0][i] ? wt.days[0][i][0][4] : undefined);var i = 2; console.log(wt.days[0][i] ? wt.days[0][i][0][4] : undefined);- Yaant