find occurences in a double array with jquery -


i had double array in jquery :

total_value_year = { {'2014', 1500}, {'2015', 1000}, {'2014', 150}, {'2015', 200}, {'2015', 50}, ... } 

there 2 years possible, want add value same years. @ end want have theses datas :

2014 => 1650, 2015 => 1250

try http://jsbin.com/sahasira/1/edit

total_value_year = [  ['2014', 1500],  ['2015', 1000],  ['2014', 150],  ['2015', 200],  ['2015', 50] ]; var arr = {}; total_value_year.foreach(   function (item, index) {     arr[item[0]] = (arr[item[0]] || 0) + item[1];   } ); console.log(arr["2014"]); console.log(arr["2015"]); 

Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -