简体   繁体   中英

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 ?

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

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);
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM