Home > database >  Angular. How can I get a value in object that is in array?
Angular. How can I get a value in object that is in array?

Time:03-19

If I need to get 59, how can I do it?

data = [
   {name: 'AK', price: 50, amount: 1, total: 50},

   {name: 'UMP', price: 59, amount: 1, total: **59**}
]

CodePudding user response:

if you are looking solution with Array iteration

for (let dt of data) {
    console.log(dt.total);
}

if you are looking for a solution on condition-based then

data.find(dt => dt.name === 'UMP').total;

CodePudding user response:

If data array is static:

 data[1].total   

else

  const getObjectHavingTotal59 = this.data.filter(e=>{
          return e.total===59;
        })

then

getObjectHavingTotal59[0].total;
  • Related