将对象数组转换为数组的分组数组

时间:2018-12-09 23:22:46

标签: javascript arrays object transform

我想知道如何改变这个

var array = [
    {group: 'one', ...},
    {group: 'one', ...},
    {group: 'two', ...},
    {group: 'two', ...},
    {group: 'three', ...},
    {group: 'three', ...},
];

对此

[
    [{group: 'one', ...}, {group: 'one', ...}],
    [{group: 'two', ...}, {group: 'two', ...}],
    [{group: 'three', ...}, {group: 'three', ...}],
]

具有相同组的每个对象应位于同一数组中。

谢谢。

0 个答案:

没有答案