使用filter可以做到去重和刪掉特定行功能
<script>
export default {
data(){
return{
tableData:[
{name:'helen',id:1},
{name:'bob',id:2},
{name:'helen',id:1},
]
}
},
methods(){
// 去掉重複數據 使用filter去重複數據
quchong(){
const res = new Map()
return tableData.filter(this.tableData=>!res.has(this.tableData.id)&&res.set(this.tableData.id,1))
}
// 刪除id爲1的所有條目 使用filter刪除特定行
shanchu(){
let tableData1 = tableData.filter(item=>item.id != 1)
}
}
}
</script>