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
}]
*/
let obj = {foo: 1, bar: 2, baz: 3}
function removeProperty(obj, propertyName) {
let newObj = {...obj};
delete newObj[propertyName];
return newObj;
}
console.log(removeProperty(obj, 'foo'));
let obj = {foo: 1, bar: 2, baz: 3}
function removeProperty(obj, propertyName) {
let { [propertyName]: _, ...result } = obj
return result
}
console.log(removeProperty(obj, 'foo'));
+-----------------------------------+
| Browser | delete | destructure |
+---------+-----------+-------------+
| Chrome | 3,229,791 | 1,993,256 |
| Safari | 1,186,679 | 1,872,396 |
+---------+-----------+-------------+