Iterating the array of objects and removing the nested object and adding in single object
Json Object:
- results: [10]
- 0: {
- hospital_details: {
site_id: "61624374", description: "ACCESS LH CALIBRATOR", name: "SOUL DIAGNOSTICS", - city: "BENGALURU"
- }
- end_customer_details : {
site_id: "61624374", description: "ACCESS LH CALIBRATOR", name: "SOUL DIAGNOSTICS", - city: "BENGALURU"
- }
- "toSalesOrder": "",
- "toSalesOrderLineNumber": "",
- "toSalesOrderLineDetailedNumber": "",
- "toInvoiceNumber": "",
- availableQuantity: 1
- cpNumber: "3061392"
- created_on: "2021-12-01T16:14:50.115995Z"
- }
- 1: {
- hospital_details: {
site_id: "61624374", description: "ACCESS LH CALIBRATOR", name: "SOUL DIAGNOSTICS", - city: "BENGALURU"
- }
- end_customer_details : {
site_id: "61624374", description: "ACCESS LH CALIBRATOR", name: "SOUL DIAGNOSTICS", - city: "BENGALURU"
- }
- "toSalesOrder": "",
- "toSalesOrderLineNumber": "",
- "toSalesOrderLineDetailedNumber": "",
- "toInvoiceNumber": "",
- availableQuantity: 1
- cpNumber: "3061392"
- created_on: "2021-12-01T16:14:50.115995Z"
- }
Output:
- end_customer_name: "IGENETIC DIAGNOSTICS PVT LTD"
- end_customer_pincode: "400072"
- end_customer_region: "WEST"
- end_customer_site_id: "46280291"
- end_customer_state: "MAHARASHTRA"
- fromEndCustomerNumber: "10195892"
- fromInvoiceNumber: "17331148051"
- "toSalesOrder": "",
"toSalesOrderLineNumber": "",
"toSalesOrderLineDetailedNumber": "",
"toInvoiceNumber": "",
availableQuantity: 1
cpNumber: "3061392"
created_on: "2021-12-01T16:14:50.115995Z"
}
res['results'].forEach((element: any, index) => {
let hospitaldetails = element.hospital_details;
let customerdetails = element.end_customer_details;
let grid = Object.assign(element, hospitaldetails, customerdetails);
this.gridData.push(grid);
});
No comments:
Post a Comment