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

based on array of object on key array list covert each key to new object of array list

"Items" having array of object in each object there is key called "ImpactedCIs" array list. Based on each array list need to generate new object based on "ImpactedCIs" array of objects. Need a possible new array of objects with an existing key element.

                  "items": [
            {
                "ImpactedCIs": ["MJUDKHJ112O","FTTM_ZTF647"],
                "CMSStatus": "5",
                "ActualStartTime": "1700003455",
                "ActualEndTime": "1700003455",
                "PM": "Sample",
                "PMContact": "45345435"
            }
        ]
                    
                Result: 
                "items": [
        {
            "ImpactedCIs": "MJUDKHJ112O",
            "CMSStatus": "5",
            "ActualStartTime": "1700003455",
            "ActualEndTime": "1700003455",
            "PM": "Sample",
            "PMContact": "45345435"
        },
        {
            "ImpactedCIs": "FTTM_ZTF647",
            "CMSStatus": "5",
            "ActualStartTime": "1700003455",
            "ActualEndTime": "1700003455",
            "PM": "Sample",
            "PMContact": "45345435"
        }
    ]

>Solution :

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

With some loops you can achieve it. In order to copy (shallow) an object I can use { ... obj }

var items = [{
  "ImpactedCIs": ["MJUDKHJ112O", "FTTM_ZTF647"],
  "CMSStatus": "5",
  "ActualStartTime": "1700003455",
  "ActualEndTime": "1700003455",
  "PM": "Sample",
  "PMContact": "45345435"
}]

var result = []
items.forEach(function(item) {
  item.ImpactedCIs.forEach(function(ImpactedCI) {
    var new_item = {... item}
    new_item.ImpactedCIs = ImpactedCI
    result.push (new_item)
  })
})

console.log(result)
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