Vue 中使用 Set 去重数组并赋值给另一个数组 - 避免重复字段
使用 Set 数据结构可以确保数组中的字段 key 是唯一的。首先,将 selectionRows 数组转换为 Set,然后将 Set 转换为数组并赋值给 this.mustMiddlegroundDifArr 数组。以下是示例代码:
// 将 selectionRows 数组转换为 Set
const set = new Set(selectionRows.map(row => row.key));
// 将 Set 转换为数组并赋值给 this.mustMiddlegroundDifArr 数组
this.mustMiddlegroundDifArr = Array.from(set);
使用 Set 的特性可以确保数组中的字段 key 是唯一的,重复的值将被自动去重。
原文地址: https://www.cveoy.top/t/topic/qlBS 著作权归作者所有。请勿转载和采集!