So I have a multidimensional array like:
myArr = [["venue",2],["venue",16],["inning",2],["inning",4],["inning",32],["hithard", 4]]
I would like to add the similar values up. So in the end I just have:
"venue" = 18, "inning" = 38, and "hithard" = 4.
Can you give me an example of how to accomplish this? Either with Javascript and/or jQuery
Thanks!
Underscore solution:
A little dirtier in jQuery
Edit: add jQuery version
DEMO: http://jsfiddle.net/Ta97E/2/
you can use values to create the query string
Check this code:
DEMO: http://jsfiddle.net/UVJEb/
I am not sure if you want an array or object. If object, stop it is 1st pass and
tmp
in below code should return you the object asObject { venue=18, inning=38, hithard=4}
.DEMO