···
例如返回:
let test = [{
type: 'T1',
usetime: 100
},
{
type: 'T2',
usetime: 200
},
{
type: 'T3',
usetime: 300
},
]
然而我们需要
let test = [{
name: 'T1',
value: 100
},
{
name: 'T2',
value: 200
},
{
name: 'T3',
value: 300
},
]
结构1: let newData= test.map((item, index) => {
let newJson= {}
newJson.name= item.type;
newJson.value= item.usetime;
return newJson
})
console.log(newData)
结构2:
let newData= test.reduce((init, value, index) => {
init.push({})
init[index].value = value.type
init[index].name = value.usetime
return init
}, [])
console.log(newData)
···