作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 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/
我是一名优秀的程序员,十分优秀!