chhaya Joshi
chhaya Joshi

Reputation: 47

How to get object which is inside array object in javascript?

 "DurationDetail" : {
  "Manual" : [ 
  {"Time" : "600000","Note" : "","TimeStamp" : ISODate("2017-01-13T06:12:22.485Z")}],
        "Automated" :{"Time" : "5000"}},

I want to access Manual.Time ? how to access that ?

Upvotes: 0

Views: 55

Answers (2)

Ankit Kumar Gupta
Ankit Kumar Gupta

Reputation: 1322

I am feeling that your code is incomplete.It should be object. Object should be

var obj = {
   "DurationDetail" : {
     "Manual" : [ 
     {"Time" : "600000","Note" : "","TimeStamp" : ISODate("2017-01-       13T06:12:22.485Z")}],
    "Automated" :{"Time" : "5000"}},
 }

ans is

obj.DurationDetail.Manual[0].Time

DurationDetail contains an object and Manual is array so you can access it by obj.DurationDetail.Manual.

0th Element contain an object with field Time.

Access by obj.DurationDetail.Manual[0].Time

Upvotes: 1

Brave Soul
Brave Soul

Reputation: 3620

If you have multiple array of manual then you can do it looping through manual array of duration detail object

for ( var i=0;i< DurationDetail.Manual.length;i++ )
 {
     console.log(DurationDetail.Manual[i].Time);
 }

Upvotes: 1

Related Questions