Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove objects from array in typescript

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!

like image 799
Bereket Gebremeskel Avatar asked Oct 16 '25 04:10

Bereket Gebremeskel


1 Answers

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;
  });
}