Vipul Singh
Vipul Singh

Reputation: 393

How to get particular Json data from array

I know there are many questions of similar topic but i could not find any answer to my problem so i am writing my code here. I have Json Data (given below) and i want to get Days field of it and compare it to another array and if the values matches certain task to perform.

    var DoctorsDetails={
               "generalPractitioner":{

                 "drg001":  {

                        "name":"Dr. Rajitha",
                        "age":"23",
                        "sex":"F",
                        "qualification":"MBBS",
                        "designation":"Duty Doctor",
                        "days":["Mon","Tue","Wed"],
                        "timef":"09:30 am",
                        "timet":"04:30 pm",
                        "slots":["1","2","3","4","5","6","7","8"]
                   },
                  "drg002": {

                        "name":"Dr. Bharadwaj",
                        "age":"23",
                        "sex":"M",
                        "qualification":"MBBS",
                        "designation":"Duty Doctor",
                        "days":["Thu","Fri","Sat"],
                        "timef":"10:30 am",
                        "timet":"02:30 pm",
                        "slots":["1","2","3","4","5","6","7","8"]
                   },
                 "drg003":  {

                        "name":"Dr. Kotesh",
                        "age":"25",
                        "sex":"M",
                        "qualification":"MBBS",
                        "designation":"Duty Doctor",
                        "days":["Sun","Thu","Sat"],
                        "timef":"09:30 am",
                        "timet":"01:30 pm",
                        "slots":["1","2","3","4","5","6","7","8"]
                   }

           },
               "physician":{
                   "drp001":
                   {


                        "name":"Dr. Dwarkanath",
                        "age":"55",
                        "sex":"M",
                        "qualification":"MBBS, DIP, CAR",
                        "designation":"General Physician",
                        "days":["Mon","Tue","Wed","Thu","Fri","Sat"],
                        "timef":"11:00 am",
                        "timet":"05:30 pm",
                        "slots":["1","2","3","4","5","6","7","8"]
                   },
                  "drp002":  {

                        "name":"Dr. Madhu Muddaiah",
                        "age":"35",
                        "sex":"M",
                        "qualification":"MBBS,MD",
                        "designation":"Consultant Physican",
                        "days":["Mon","Tue","Wed","Thu","Fri","Sat"],
                        "timef":"02:30pm",
                        "timet":"08:30pm",
                        "slots":["1","2","3","4","5","6","7","8"]
                   },
                  "drp003": {

                        "name":"Dr. Arvind",
                        "age":"35",
                        "sex":"M",
                        "qualification":"MBBS,MD",
                        "designation":"Consultant Physican",
                        "days":["Mon","Tue","Wed","Thu","Fri","Sat"],
                        "timef":"10:30 am",
                        "timet":"03:30 pm",
                        "slots":["1","2","3","4","5","6","7","8"]
                   }   
           },
    };
 console.log(DoctorsDetails["generalPractitioner"]deg001.days);

so this will give me the days of drg001 only but i want days for all the ids to to be shown/captured.

For getting days of each id what code I have to write? I know I have to use .each function but how do i get these ids name automatically.

Upvotes: 1

Views: 72

Answers (1)

Siddharth
Siddharth

Reputation: 869

try this, you can extract any field using this.

$.each(DoctorsDetails.generalPractitioner,function(i,v){
   console.log(v.days);
 });

Upvotes: 1

Related Questions