我有一个这样的 JavaScript 对象:
[{"a":1,"b":2},{"a":1,"b":3},{"a":2,"b":4},{"a":2,"b":5}]
我想将此对象字段'a'分组并想要这样的东西:
[{"a":1,"values":[{"a":1,"b":2},{"a":1,"b":3}]},{"a":2,"values":[{"a":2,"b":4},{"a":2,"b":5}]}]
我有一个包含数千个元素的 JavaScript 数组。实现这一目标的最有效方法是什么?