1 回答

TA贡献1898条经验 获得超8个赞
var users = [
{id: 1, username: '123', authPlayerIds: [1001, 1002, 1003]},
{id: 2, username: 'qwe', authPlayerIds: [1003, 1004, 1005]},
{id: 3, username: 'fdf', authPlayerIds: [1002, 1007, 1088]},
{id: 4, username: 'dsa', authPlayerIds: [1001, 1022, 1033]},
]
var ret = {}
users.forEach(function(e){
var ap = e.authPlayerIds
ap.forEach(function(p){
var t = {}
if (ret[p]) {
t.id = e.id || null
t.username = e.username || null
} else {
ret[p] = []
t.id = e.id || null
t.username = e.username || null
}
ret[p].push(t)
})
})
添加回答
举报