Dewz Khachornphop
Dewz Khachornphop

Reputation: 11

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

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**}
]

Upvotes: 0

Views: 80

Answers (2)

Tariq Aqeel
Tariq Aqeel

Reputation: 93

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;

Upvotes: 1

devj
devj

Reputation: 387

If data array is static:

 data[1].total   

else

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

then

getObjectHavingTotal59[0].total;

Upvotes: 0

Related Questions