1. 效果对比
说明:左侧原数据,右侧处理后
2. 代码实现
test() {
let a = [
{
city: '白云',
data: [1, 2, 3, 4, 5, 6]
},
{
city: '黑土',
data: [1, 2, 3, 4, 5, 6]
}
]
let newData = a.map(item => item.data.splice(0, 2))
a.forEach(function (currentValue, index) {
currentValue['data'] = newData[index]
})
}