score:7

Accepted answer

You can do it like this

var arr = [{
    ReductionID:5813,
    PatientID: 945994,
    ProviderAcctNumber:"",
    Discharge: "945994 : 01/01/0001 - 01/01/001",
    Selected: 1,
    Balance: 20,
    Charges: 10
}];

var updatedArr = arr.map((obj)=>{
    return {
        PID:obj.PatientID,
        selection:obj.Selected
    }
});

console.log(updatedArr);

Here we iterate over the original array using map and select the values we need & return the Object as required

score:5

map here is the best approach for you. You can simply do:

var reduction = [
    {
        ReductionID: 5813,
        PatiendID: 945994,
        ProviderAcctNumber: "",
        Discharge: "945994 : 01/01/0001 - 01/01/001",
        Selected: 1,
        Balance: 20,
        Charges: 10
    }
]
 const patientDetails = reduction.map(({PatiendID,Selected}) => ({PID: PatiendID, selection: Selected}))
 
 console.log(patientDetails) //  [{"PID": 945994, "selection": 1}]

Here callback function of map iterates over each elements reduction and returns a new object with only PID and selection


Related Query

More Query from same tag