Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Typescript/Angular – Creating a child array containing specific property of Parent JSON object

I have a parent object containing the following data

[
    {
        "BEGIN_TIME": "24 Feb 2023 13:36",
        "END_TIME": "24 Feb 2023 13:37",
        ...
    },
    {
        "BEGIN_TIME": "24 Feb 2023 13:37",
        "END_TIME": "24 Feb 2023 13:38",
        ...
    },
    {
        "BEGIN_TIME": "24 Feb 2023 13:38",
        "END_TIME": "24 Feb 2023 13:39",
        ...
    }
]

I want to create an array containing specific property of a parent object.
For instance, I need all values of END_TIME property. Something like following

child_array=parent_json.Get(END_TIME);

Expected result

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

["24 Feb 2023 13:37","24 Feb 2023 13:38","24 Feb 2023 13:39"]

>Solution :

You can use map function

const child_array = parent_json.map(obj => obj.END_TIME);

console.log(child_array);
// Output: ["24 Feb 2023 13:37", "24 Feb 2023 13:38", "24 Feb 2023 13:39"]

Enjoy with this

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading