我有一个地图数组,如果它存在,我想从中删除一个元素,这由它的“键”确定。
怎么做?我希望它不慢。保持顺序并不重要。
myMaps = []map[string]interface{} {
map[string]interface{} {"key": "aaa", "key2": 222, "key3": "aafdsafd"},
map[string]interface{} {"key": "key_to_delete", "key2": 366, "key3": "333aafdsafd"},
map[string]interface{} {"key": "cccc", "key2": 467, "key3": "jhgfjhg"},
}
for _, x := range myMaps {
if x["key"] == "key_to_delete" {
//delete this element as a) key of the map b) the map-element as an element of the array; How?
}
}
delete(...)功能:
当迭代一个数组时,它的副本是在循环体中传递的。不?那么如何delete(...)从真实数组中删除一个元素?
更新:
我需要知道如何删除 2 类实体,就我而言:
数组的一个元素 - 一张地图
地图的一个元素,具有特定的键
不使用第三方库。
繁星淼淼
相关分类