js如何把下列数据处理成目标想要的数据 ?-灵析社区

生成头像

js数据结构处理 后台返回的接口数据如下 { "result": [ { "name": "参数1", "secondName": [ "高度", "马赫数" ] }, { "name": "参数2", "secondName": [ "前向", "垂向", "侧向" ] }, { "name": "参数3", "secondName": [ "前向", "垂向", "侧向" ] }, { "name": "参数4", "secondName": [ "前向", "垂向", "侧向" ] }, { "name": "参数5", "secondName": [ "前向", "垂向", "侧向" ] }, { "name": "参数6", "secondName": [ "前向", "垂向", "侧向" ] } ], "success": true } 想把res.result变成如下格式 js数据结构处理后台返回的接口数据如下 { "result": [ { "name": "参数1", "secondName": ‘高度‘ }, { "name": "参数1", "secondName": ‘马赫数‘ }, { "name": "参数2", "secondName": "前向", }, { "name": "参数2", "secondName": "垂向", }, { "name": "参数2", "secondName": "侧向", }, } 以此类推.... 没有思路,求指点

阅读量:17

点赞量:0

问AI
光光哥乌昂
reduce功能很强大,可以学习下 result.reduce((arr, item) => arr.concat(item.secondName.map((sitem, sindex) => ({name: item.name, secondName: sitem, index: arr.length + sindex}))), [])