how do i remove object from an array in typescript?
"revenues":[
{
"drug_id":"20",
"quantity":10
},
{
"drug_id":"30",
"quantity":1
}]
so i want to remove the drug_id from all objects. how do i achieve that? Thank You!
you could use that :
this.revenues = this.revenues.map(r => ({quantity: r.quantity}));
For a more generic way of doing this :
removePropertiesFromRevenues(...props: string[]) {
this.revenues = this.revenues.map(r => {
const obj = {};
for (let prop in r) { if (!props.includes(prop) { obj[prop] = r[prop]; } }
return obj;
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With