Golang切片数组如何去重
如下是Golang的一个切片,里面有重复的值,下面我们一起看看Golang切片数组如何去重
[
{
Title: "3584.txt",
FullPath: "3584.txt",
IsFolder: false,
IsFile: true,
Suffix: ".txt",
Size: 0,
ModifyTime: "2023-04-23T03:37:58Z"
},
{
Title: "3584.txt",
FullPath: "3584.txt",
IsFolder: false,
IsFile: true,
Suffix: ".txt",
Size: 0,
ModifyTime: "2023-04-23T03:37:58Z"
},
{
Title: "aa",
FullPath: "aa/",
IsFolder: true,
IsFile: false,
Suffix: "",
Size: 0,
ModifyTime: "2023-04-23T05:42:05Z"
},
{
Title: "realm.zip",
FullPath: "realm.zip",
IsFolder: false,
IsFile: true,
Suffix: ".zip",
Size: 3829,
ModifyTime: "2023-04-23T06:36:33Z"
},
{
Title: "test",
FullPath: "test/归档.zip",
IsFolder: true,
IsFile: false,
Suffix: "",
Size: 452090,
ModifyTime: "2023-04-23T07:08:50Z"
},
{
Title: "test",
FullPath: "test/归档.zip",
IsFolder: true,
IsFile: false,
Suffix: "",
Size: 452090,
ModifyTime: "2023-04-23T07:08:50Z"
}
]
Golang切片数组如何去重的方法
for i := 0; i < len(list); i++ {
for j := 0; j < len(list); j++ {
if list[i].Title == list[j].Title && i != j { //将后面重复的数删掉
list = append(list[:j], list[j+1:]...)
}
}
}