The original data:
{name: zhang SAN},
{name: li si},
{name: fifty},
{name: find six}
]
Form new data for:
[{name: zhang SAN}, {name: li si}],
[{name: fifty}, {name: zhao six}]
]
CodePudding user response:
Problem has been solved, scattered points tomorrowCodePudding user response:
66CodePudding user response:
Although the original poster is solved, but still try to write the
Arr. Reduce ((obj, v, I)=& gt; {
If (I % 2===0) {
Obj [obj. Length]=[v]
} else {
Obj [obj. Length - 1]. Push (v)
}
Return obj
}, [])
CodePudding user response:
Var arr=[
{name: "* *"},
{name: "bill"},
{name: "detective"},
{name: "find six"}
];
Var arr2=[];
For (var I=0; I & lt; Arr. Length; I +=2)
Arr2. Push (arr. Slice (I, I + 2));
The console. The log (arr2);