Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

remove a property from an object javascript using spread operator

const response = [{
    drugName: 'HYDROCODONE-HOMATROPINE MBR',
    drugStrength: '5MG-1.5MG',
    drugForm: 'TABLET',
    brand: false
},
{
    drugName: 'HYDROCODONE ABC',
    drugStrength: '10MG',
    drugForm: 'SYRUP',
    brand: true
}]

const output = response.map(({ drugName, ...rest }) => rest)

/* output = [{
    drugStrength: '5MG-1.5MG',
    drugForm: 'TABLET',
    brand: false
},
{
    drugStrength: '10MG',
    drugForm: 'SYRUP',
    brand: true
}]
*/
 
PREVIOUS NEXT
Tagged: #remove #property #object #javascript #spread #operator
ADD COMMENT
Topic
Name
4+3 =