代码拉取完成,页面将自动刷新
基于 reflect 的应用,实现 go 语言 Array(Slice/Map) 常用工具函数,具体的函数方式下面有详细内容讲解。
// github
go get github.com/lihao1988/go-array
// gitee
go get gitee.com/lihao1988/go-array
Go 1.15 or above.
// 用于检查Array(Slice/Map)中是否存在指定的值
value = "a"
dataMap := []string{"a", "b", "c"}
isExist := In(value, dataMap)
fmt.Println(isExist)
// 获取数组中所有的键名
dataMap := map[string]string{
"a": "this is 'A'",
"b": "this is 'B'",
}
var keys []string
Keys(dataMap, &keys)
fmt.Println(keys)
// 获取数组中所有的值
dataMap := map[string]string{
"a": "this is 'A'",
"b": "this is 'B'",
}
var values []string
Values(dataMap, &values)
fmt.Println(values)
// 把一个或多个数组合并为一个数组
dataMap := map[string]string{
"a": "this is 'A'",
"b": "this is 'B'",
}
dataOne := map[string]string{
"c": "this is 'C'",
}
dataTwo := map[string]string{
"d": "this is 'D'",
}
Merge(&dataMap, dataOne, dataTwo)
fmt.Println(dataMap)
// 删除数组中的重复值
dataMap := map[int]string{
"a": "this is 'A'",
"b": "this is 'B'",
"a": "this is 'A'",
}
Unique(&dataMap)
fmt.Println(dataMap)
// 返回输入数组中某个单一列的值
dataMap := map[string]map[string]string{
"a": {"key": "a1", "value": "A"},
"b": {"key": "b1", "value": "B"},
}
// key 使用子数组字段 'key',column 为子数组内容
dest := map[string]map[string]string{}
Column(&dest, dataMap, "", "key")
fmt.Println(dest)
//key 使用子数组字段 'key',column 使用子数组字段 'value'
dest := map[string]string{}
Column(&dest, dataMap, "value", "key")
fmt.Println(dest)
//key 为空则为 list,column 使用子数组字段 'value'
dest := []map[string]string{}
Column(&dest, dataMap, "value", "")
fmt.Println(dest)
// 比较数组,返回差集(只比较键值)
dataMap := map[int]string{
"a": "this is 'A'",
"b": "this is 'B'",
"c": "this is 'C'",
}
dataOne := map[int]string{
"b": "this is 'B'",
"d": "this is 'D'",
}
dataTwo := map[int]string{
"c": "this is 'C'",
"e": "this is 'E'",
}
Diff(&dataMap, dataOne, dataTwo)
fmt.Println("dataMap", dataMap)
// 比较数组,返回交集(只比较键值)
dataMap := map[int]string{
"a": "this is 'A'",
"b": "this is 'B'",
}
dataOne := map[int]string{
"b": "this is 'B'",
"d": "this is 'D'",
}
dataTwo := map[int]string{
"c": "this is 'C'",
"e": "this is 'E'",
}
Intersect(&dataMap, dataOne, dataTwo)
fmt.Println("dataMap", dataMap)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。