(修改字段名)转换数组对象的字段名
//es6
var list = [
{
username: '网易',
coverame: '有易'
},
{
username: '为易',
coverame: '和易'
},
]
var newItems = list.map(el => {
return {
name: el.username,
timeSlot: el.coverame
}
})
//console.log(newItems)
// newItems = [{name: "网易",timeSlot: "有易"},{name: "为易",timeSlot: "和易"}]
//es5
var array = [
{
username: '网易',
coverame: '有易'
},
{
username: '为易',
coverame: '和易'
},
]
var newArray= array.map(function(el) {
return {
name: el.username,
timeSlot: el.coverame
}
});
//console.log(newArray)
// newArray = [{name: "网易",timeSlot: "有易"},{name: "为易",timeSlot: "和易"}]