定义集合
let showList = [
{name: '西游记', id: 1, content: "hhh"},
{name: '三国演义', id: 2, content: "hhh"},
{name: '水浒传', id: 3, content: "hhh"},
{name: '红楼梦', id: 4, content: "hhh"}
]
将集合转成map
let map = {}
this.showList.forEach(row => {
map[row.id] = {name: row.name, content: row.content}
})
console.log(map)
将map转成集合
let array = []
for(let key in map) {
let obj = map[key]
obj.id = key
array.push(obj)
}
console.log(array)