gpt4 book ai didi

javascript - 如何在 React Native 中更改数组键名称

转载 作者:行者123 更新时间:2023-12-05 09:10:22 26 4
gpt4 key购买 nike

我是 api 响应,我正在获取下面的数组作为响应。我必须更改数组的内部键名称,然后发送到 ui 。请帮忙 。我很困惑。

"callDetails": [
{
"quantity":5,
"msisdn":1,
"otherMSISDN": 2348032002207
},
{
"quantity": 5,
"msisdn": 2347062021398,
"otherMSISDN": 2347038834140
},
{
"quantity": 4,
"msisdn": 2347062021398,
"otherMSISDN": 2348166692364
},
]

//我必须将我的数组从上方数组转换为下方数组。

"callDetails": [
{
"frquency":5,
"totalRows":1,
"frequentNumber": 2348032002207
},
{
"frquency": 5,
"totalRows": 1,
"frequentNumber": 2347038834140
},
{
"frquency": 4,
"totalRows": 1,
"frequentNumber": 2348166692364
},
]

最佳答案

您可以使用 Array.map()要实现这一点,可以这样做:

const response = {

"callDetails": [
{
"quantity":5,
"msisdn":1,
"otherMSISDN": 2348032002207
},
{
"quantity": 5,
"msisdn": 2347062021398,
"otherMSISDN": 2347038834140
},
{
"quantity": 4,
"msisdn": 2347062021398,
"otherMSISDN": 2348166692364
}
]

}

response.callDetails = response.callDetails.map(({quantity, msisdn, otherMSISDN}) => {
return {
frquency: quantity,
totalRows: msisdn,
frequentNumber: otherMSISDN
}
});

console.log(response)

关于javascript - 如何在 React Native 中更改数组键名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61590369/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com