【发布时间】:2020-09-15 13:45:02
【问题描述】:
我有对象列表数据。 我必须按值对唯一标识进行明智的排序。以及它们的数据存储各自的唯一标识对象。 ** 对象列表 **
{
uniqueid : 200,
name : "sandesh",
loop: 222,
salary : 2500
},
{
uniqueid : 300,
name : "hello",
loop: 222,
salary : 2500
},
{
uniqueid : 300,
name : "hello1",
loop: 222,
salary : 2500
};
我将明智地创建一个对象 uniqueid 并在那里存储值,但每个数据都会创建重复的对象。
var newArray = [];
this.userBetHistory.forEach(item => {
var newItem = {uniqueid : item.uniqueid, BetData: []};
this.userBetHistory.forEach(innerItem => {
if(innerItem.uniqueid== item.uniqueid){
newItem.BetData = newItem.BetData.concat(innerItem);
}
});
newArray.push(newItem);
});
** 预期输出:**
{
uniqueid : 200,
data :
{
uniqueid : 200,
name : "sandesh",
loop: 222,
salary : 2500
}
},
{
uniqueid : 300,
data :
{
uniqueid : 300,
name : "hello",
loop: 222,
salary : 2500
},
{
uniqueid : 300,
name : "hello1",
loop: 222,
salary : 2500
}
}
【问题讨论】:
-
预期输出不是有效的 JSON。
标签: javascript arrays object filter