0

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**}
]
2
  • 5
    data[1].total? Commented Mar 18, 2022 at 18:35
  • I think some more clarification would help get a more suitable answer. Like others have said, are you searching for a specific value which is dynamically generated? are you always just looking for a value of 59? are you looking for that total b/c of the name on the object. I think you see what i mean, since there are several very simple ways to do this, however if you are handling dynamic data it makes things somewhat more complicated Commented Mar 18, 2022 at 19:21

2 Answers 2

1

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;
Sign up to request clarification or add additional context in comments.

Comments

0

If data array is static:

 data[1].total   

else

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

then

getObjectHavingTotal59[0].total;

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.