我怎样才能array.reduce
改变数组内容的方式。我不想对内容做任何数学运算。
原始数组:
var myArray = [
{id:1, name:'name01', value:11},
{id:2, name:'name02', value:22},
{id:3, name:'name03', value:33},
{id:4, name:'name04', value:44},
{id:5, name:'name05', value:55}
]
我希望将其更改为:
[
{1:{id:1, name:'name01', value:11}},
{2:{id:2, name:'name02', value:22}},
{3:{id:3, name:'name03', value:33}},
{4:{id:4, name:'name04', value:44}},
{5:{id:5, name:'name05', value:55}}
]
所以 the是从as aid
中弹出的,而它是整个.object
key
value
object
这可以通过array.reduce
不使用任何for loop
or来实现groupBy
吗?