2

I want to parse driverDocumentDetails like an Array.

JSON is implemented from android (Java) HashMap data structure Angular Firestore MAP inside MAP

{ 
   "driverDocumentDetails":{ 
      "fhgfh":{ 
         "documentCategoryID":"fhgfh",
         "documentCategoryName":"Pan Card",
         "documentUploadedDateTime":null,
         "reasonForRejection":null,
         "uploaded":false,
         "uploadedDocumentURL":null,
         "verified":false
      },
      "bjhbh":{ 
         "documentCategoryID":"bjhbh",
         "documentCategoryName":"Driving License",
         "documentUploadedDateTime":null,
         "reasonForRejection":null,
         "uploaded":false,
         "uploadedDocumentURL":null,
         "verified":false
      },
      "hgvjh":{ 
         "documentCategoryID":"hgvjh",
         "documentCategoryName":"NOC",
         "documentUploadedDateTime":null,
         "reasonForRejection":null,
         "uploaded":false,
         "uploadedDocumentURL":null,
         "verified":false
      }
   },
   "driverID":"bhbjhbjhbj",
   "hgchg":[ 
      { 
         "bjnk":"jhbjhb",
         "fhfyhgf":"jjb"
      },
      { 
         "gfhg":"jgjuy",
         "gh":"guguj"
      }
   ]
}
onCustom(recordRow) {
    console.log("onCustom Driver docs data---->",recordRow);
    this.crudService.ReadDriverDocuments(recordRow.data.id).subscribe(data => {

    this.driverDocument = data.data();
    console.log('ReadDriverDocuments',this.driverDocument);
    });
  }
4
  • Do the proper formating Commented Oct 22, 2019 at 13:47
  • Why your question contains unwanted commented code? Post it as a try:) Commented Oct 22, 2019 at 13:49
  • What is the output of console.log('ReadDriverDocuments',this.driverDocument);? Commented Oct 22, 2019 at 13:50
  • just simple declare one list: arr = []; arr.push(obj); Commented Oct 22, 2019 at 13:56

1 Answer 1

2

You can use Object.keys to get the keys and then map it into a new array:

var driverDocumentDetailsArray = Object.keys(this.driverDocument.driverDocumentDetails)
    .map(key => this.driverDocument.driverDocumentDetails[key]);

Or if it's available, just Object.values

var driverDocumentDetailsArray = Object.values(this.driverDocument.driverDocumentDetails);
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.