0

I have an array of objects that looks like this:

[
    {
        "e_id": "1",
        "total": 0
    },
    {
        "e_id": "3",
        "total": 0
    }
]

Within a forEach loop, I want to increment the total value depending on the e_id. I have been trying something like this:

e.forEach((row) => {
    this.arrayObj[row.e_id]['total']++;
});

But this does not work as I think it is using the e_id as an index as opposed to a reference.

Is there a way this can work?

AbsoluteBeginner
  • 2,160
  • 3
  • 11
  • 21
nimgwfc
  • 1,294
  • 1
  • 12
  • 30

1 Answers1

1
e=[
    {
        "e_id": "1",
        "total": 0
    },
    {
        "e_id": "3",
        "total": 0
    }
]

e.forEach((row) => {
    row['total']++;
});

Do you need this?

pullidea-dev
  • 1,768
  • 1
  • 7
  • 23