我正在使用AWS Cognito listUsers API从我的Cognito池中获取所有用户的列表。我已经成功地返回了用户数组,但现在我被困在如何将该数组转换为扁平数组上。以下是我从AWS listUsers API收到的数据示例:
[
{
Username: "xx001",
Attributes: [
{
Name: "given_name",
Value: "Jeff"
},
{
Name: "family_name",
Value: "Smith"
},
{
Name: "email",
Value: "jeff.smith@email.com"
}
],
UserStatus: "Confirmed",
},
{
Username: "yy002",
Attributes: [
{
Name: "given_name",
Value: "Steve"
},
{
Name: "family_name",
Value: "Jones"
},
{
Name: "email",
Value: "steve.jones@email.com"
}
],
UserStatus: "Confirmed",
}
]
我想把上面的数组转换成下面的结构:
[
{
Username: "xx001",
given_name: "Jeff",
family_name: "Smith",
email: "jeff.smith@email.com",
UserStatus: "Confirmed"
},
{
Username: "yy002",
given_name: "Steve",
family_name: "Jones",
email: "steve.jones@email.com"
UserStatus: "Confirmed"
}
]
如果有人能给我指出正确的方向,我将不胜感激!
1条答案
按热度按时间hl0ma9xz1#
你可以使用
map
来转换数组如果属性是固定的,而不是动态的,你甚至不必使用
reduce
和spread。因此,这将比第一个更快。