当前数组:
var test = [
{
id: 1, str: 'a1', str2: 'b1' },
{
id: 2, str: 'a4', str2: 'b4' },
{
id: 1, str: 'a5', str2: 'b5' },
{
id: 3, str: 'a7', str2: 'b7' },
{
id: 2, str: 'a8', str2: 'b8' },
];
目标数组,合并所有id相同的项,生成如下数组
var newTest = [
{
id: 1,
txtArr: [{
str: "a1", str2: "b1" }, {
str: "a5", str2: "b5" }]
},
{
id: 2,
txtArr: [{
str: "a4", str2: "b4" }, {
str: "a