I have a dynamic JavaScript array that is being created on my page (none of these numbers will ever be the same, many variations), for example:
myArray[ 1 ] = [295518, 2];
myArray[ 2 ] = [123518, 123];
myArray[ 3 ] = [295518, 43];
myArray[ 4 ] = [295518, 65];
myArray[ 5 ] = [234518, 3];
myArray[ 6 ] = [567518, 56];
Explanation of this array:
[id number, quantity]
myArray[ 1 ] = [295518, 2];
I need to group all of the like id array elements together and sum their values.
For instance: 295518 would add 2 + 43 + 65 = 110
Then I need it to update the id on the page with the value:
$("#295518").text(110);
So what I am thinking is this, but I am not sure how to write it in JavaScript:
[start JavaScript loop]
[grab distinct ids]
[start id loop]
[grab all values based on id]
[sum their qty values]
[set the id element on the page with the sum value]
[example: $("#295518").text(110); ]
[end id loop]
[/end JavaScript loop]