I'm learning TypeScript and Angular and I'm struggling with a problem.
Say, I have an array of Application objects.
Each Application object has this kind of a nested structure:
Application
|
----[Document Type]
---------|
--------------[Document]
------------------|
------------------------Metadata
(Each Application has an array of Document Type.
Each Document Type has an array of Document.
Each Document has a Metadata inside it)
Example:
[
{
"name": "Application 1",
"parent_type": "root",
"children": [
{
"name": "Operations Manual",
"parent": "Application 1",
"parent_type": "application",
"count": 2,
"children": [
{
"name": "App1-OpManual-1",
"metadata": {
"actualDocName": "operations1-app1",
"currentStatus": "for review",
"lastModifiedBy": "user 1",
"size": 56,
"fileExtension": "docx"
}
},
{
"name": "App1-OpManual-2",
"metadata": {
"actualDocName": "operations2-app1",
"currentStatus": "for review",
"lastModifiedBy": "user 2",
"size": 56,
"fileExtension": "pdf"
}
}
]
}
]
}
]
I'm trying to reduce this array to this (basically, to retain the nesting only till level 2 and discard the rest):
Application
|
----[Document Type]
..so that, the JSON becomes like this:
[
{
"name": "Application 1",
"parent_type": "root",
"children": [
{
"name": "Operations Manual",
"parent": "Application 1",
"parent_type": "application",
"count": 2
}
]
}
]
I've been trying with multiple examples from tutorials, but haven't been able to get the correct JS to do this. Can anybody please help?
I've been tryingshow what you've tried, perhaps it's a simple mistake you've made in your attempt - you'll learn more from having your mistake corrected rather than having the code written for you with no apparent attempt by you