Looking for the fastest and the best way to group an array of objects in Javascript
Have a an array of objects as
[{'gHeader': 'gH1', 'key1' : 'val11'}, {'gHeader': 'gH2', 'key1' : 'val11'}, {'gHeader': 'gH1', 'key1' : 'val12'}, {'gHeader': 'gH2', 'key1' : 'val13'}, {'gHeader': 'gH3', 'key1' : 'val14'}]
I want to know the best way to group the above array to another array as:
[{'gHeader' : 'gH1', data: [{'key1' : 'val11'}, {'key1' : 'val12'}]}, {'gHeader' : 'gH2', data: [{'key1' : 'val11'}, {'key1' : 'val13'}]}, {'gHeader' : 'gH3', data: [{'key1' : 'val14'}]}]
Notice that we need the grouping on the key 'gHeader' and introduced the key 'data' that has the value of type array. Whats the best way to do this in JAVASCRIPT?