假设一个数组长这样
var qq = [
{
"group": 100,
"info": {"event": 123},
"main": true,
},
{
"group": 100,
"info": {"event": 323},
"main": false,
"sp": 12
},
{
"group": 103,
"info": {"event": 123},
"main": true,
"sp": 13,
},
{
"group": 103,
"info": {"event": 323},
"main": false,
"sp": 10
},
{
"group": 103,
"info": {"event": 123},
"main": false,
"sp": 1
}
];
group是同数字表示是一组的,
我想要把同一组的放在一起,
還有一個特殊情况,sp===1的话,就把它放到前一个阵列的最后一个位置
也就是最后输出要这样
var qq = [
[
{
"group": 100,
"info": {"event": 123},
"main": true,
},
{
"group": 100,
"info": {"event": 323},
"main": false,
"sp": 12
},
{
"group": 103,
"info": {"event": 123},
"main": false,
"sp": 1
}
],
[
{
"group": 103,
"info": {"event": 123},
"main": true,
"sp": 13,
},
{
"group": 103,
"info": {"event": 323},
"main": false,
"sp": 10
}
]
];
这样具体该怎么实现?
试试这样如何?