1

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.

3
  • Please add the code of your best attempt for solving the problem. Commented Jan 12, 2016 at 10:02
  • Array.prototype.map(); Commented Jan 12, 2016 at 10:08
  • On click of button I am getting the id which i have assigned to button and using that id I am getting the Days. But i want it to be dynamically change without onclick or when ever page loads. ` $('.glphid').click(function(){ calId=$(this).attr('id'); $.each(DoctorsDetails["generalPractitioner"][calId].days,function(key,value){ console.log(value); }); });` Commented Jan 12, 2016 at 10:36

1 Answer 1

1

try this, you can extract any field using this.

$.each(DoctorsDetails.generalPractitioner,function(i,v){
   console.log(v.days);
 });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.